1.新建一个features包,在新建一个steps包
2.新建一个register.features文件
#coding=utf-8
Feature:Register User
As a developer
This is my first bdd project
Scenario:open register website
When I open the register website
Then I expect that title is "注册"
3.新建一个environment文件
#coding=utf-8
from selenium import webdriver
def before_all(context):
context.driver=webdriver.Chrome()
def after_all(context):
context.driver.close()
4.新建一个register_user的python文件
#coding=utf-8
from behave import *
use_step_matcher('re')
@when('I open the register website')
def step_register(context):
context.driver.get("http://www.5itest.cn/register")
@then('I expect that title is "([^"]*)"')
def step_register1(context,title_name):
title=context.driver.title
assert title_name in title
4.要在命令运行 behave