Behave 简明教程
Behave - First Steps
让我们创建一个基本的 Behave 测试。
Feature File
标题为支付类型的功能文件的示例如下 −
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
Corresponding Step Implementation File
上述功能对应的步骤实现文件如下 −
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')
Project Structure
功能“支付类型”的项目结构如下 −
Output
运行功能文件后获得的输出如下,此处使用的命令为 behave
输出显示功能和场景名称,以及测试结果和测试执行的持续时间。
Python 控制台输出如下 −