Behave - 入门



让我们创建一个基本的 Behave 测试。

特性文件

特性的特性文件如下所示:

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

Running the Feature File

该输出显示了特性和场景名称,以及测试结果和测试执行持续时间。

Python 主机输出如下所示:

Python Console
广告
© . All rights reserved.