Behave 步骤实现

Behave 步骤实现

在Behave的特征文件中,Scenario的步骤应该有用Python编写的实现逻辑。这被称为实现/步骤定义文件(扩展名为.py),应该存在于步骤目录中。

所有必要的导入都存在于这个文件中。步骤目录应该是特性目录的一部分。

The following screen will appear on your computer −

Behave 步骤实现

步骤定义文件包含Python函数,用于定义特征文件中的步骤。在Python函数的开头,必须要有以@given@when等开头的装饰器。这些装饰器与特征文件中的Given、Then、When和其他步骤进行比较和匹配。

特征文件

特征文件的内容如下

Feature  Verify book name added in Library
   Scenario  Verify Book name
      Given Book details
      Then Verify book name
Python

相应的步骤执行文件

The corresponding step implementation file looks like the one mentioned below −

from behave import *
@given('Book details')
def impl_bk(context):
      print('Book details entered')
@then('Verify book name')
def impl_bk(context):
      print('Verify book name')
Python

输出

运行特征文件后得到的输出结果如下

Behave 步骤实现

输出显示了特征和场景名称,以及测试结果和测试执行的时间。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册