cucumber测试中的feature file


cucumber测试中的feature file

feature file是cucumber工具必不可少的部分,用于编写自动化测试的验收步骤。验收步骤通常遵循应用程序规范。

feature file通常是一个公共文件,用于存储要测试的feature, scenarios, and feature描述。

feature file是一个入口点,用于编写cucumber测试并在测试时用作实时文档。

黄瓜测试中的特征文件

feature file的扩展名为“ .feature ”。软件的每个功能都必须有一个单独的功能文件。

例子:

为了确保登录功能的工作,我们正在通过创建一个feature file来实现cucumber测试。它将验证登录功能是否正常工作。

Feature: Login 
Scenario: Login Functionality
Given user navigates to the website javatpoint.com
And there user logs in through Login Window by using Username as "USER" and Password as "PASSWORD"
Then login must be successful.

执行自动化测试后,会创建一个表作为自动化测试的结果。该表用于标签。

结果表如下表所示:

黄瓜测试中的特征文件

具有多个Scenario的特征文件

功能文件可以包含多个Scenario或scenario outlines。我们可以在feature file中编写特定feature的所有可能Scenario。

黄瓜测试中的特征文件

通过使用关键字“Scenario”或“Scenario Outline”,可以将一个Scenario与另一个Scenario分开。

但是,单个功能文件可以包含任意数量的Scenario,但一次仅关注一个功能,例如注册、登录等。因此,最好将与特定功能相关的Scenario保存在单个功能文件中。

Scenario可以并行执行,也可以成组一起执行。为了更清楚,让我们举一个例子:

例子:

功能文件 1:

Feature: Registration 
Background: 
Given user on the homepage  
And user follows "Sign in"  
@regression  
Scenario: Create a New User 
When user fills "registration email textbox" with "chitrali.sharma27@gmail.com"  
And user clicks "create an account button"  
And user enters the following details 
| First Name | Chitrali| 
| Last Name | Sharma| 
| Password | Inquiry@1234 | 
| Date | 17| | Month | 02| | Year | 1992 |  
And user clicks "register button"
Scenario: User does not follow form validations
When user enters wrong characters
Then error message displayed with invalid password
And user returns back on registration page

功能文件 2:

Feature: Login
Background: 
Given user on the login page  
And user follows "Log in"  

@regression @smoke
Scenario: Verification of Login Function  
Given user on the Login Page
And user enters "email address" with "chitrali.sharma27@gmail.com" 
And user enters "password" with "Inquiry@1234"  
And user click "log in" button
Then user should see "My Account" 
Scenario: Unsuccessful login
Given user on the Login Page
And user enters "email address" with "chitrali.sharma27@gmail.com" 
And user enters "password" with "qsder@1234"  
And user clicks "login" button
Then error message displayed with wrong password
And user returns back on login page

功能文件中的注释

如果我们不需要一次执行特定的场景,那么我们可以评论该场景。

在 Eclipse 中,要注释多行或使用块注释,首先选择要注释的所有行,然后按Ctrl + /。同样,要删除注释,我们需要按Ctrl + \。其他 IDE 可能包含其他快捷方式来执行此操作。

在评论任何场景时,不要忘记评论完整的场景。否则,未注释的剩余场景行将被视为前一个场景的一部分。