Behave - 第一步
让我们创建一个基本的 Behave 测试。
特征文件
标题为"Payment Types"(支付类型)的功能文件如下 −
Feature − Payment Types
Scenario − Verify user has two payment options
Given User is on Payment screen
When User clicks on Payment types
Then User should get Types Cheque and Cash
对应步骤实现文件
上述功能对应的步骤实现文件如下 −
from behave import *
@given('User is on Payment screen')
def impl_bkpy(context):
print('User is on Payment screen')
@when('User clicks on Payment types')
def impl_bkpy(context):
print('User clicks on Payment types')
@then('User should get Types Cheque and Cash')
def impl_bkpy(context):
print('User should get Types Cheque and Cash')
项目结构
"Payment Types"(支付类型)功能的项目结构如下 −
输出
运行特征文件后得到的输出如下,这里使用的命令是behave
输出显示功能和场景名称,以及测试结果和测试执行的持续时间。
Python 控制台输出如下 −

