Cucumber教程

Cucumber Feature文件

Cucumber 测试中的Feature文件

Feature文件是Cucumber 工具中必不可少的部分,用于编写自动化测试的验收步骤。验收步骤通常遵循应用程序规范。
特性文件通常是一个公共文件,其中存储了特性、scenarios 和要测试的特性描述。
特性文件是一个入口点,用于编写Cucumber测试并用作现场文档测试时间。
Cucumber测试中的Feature文件
Feature文件的扩展名为".feature"。软件的每个功能都必须有一个单独的Feature文件。

示例:

为了确保登录功能的工作,我们正在通过创建Feature文件。它将验证登录功能是否正常工作。
Feature: Login 
Scenario: Login Functionality
Given user navigates to the website lidihuo.com
And there user logs in through Login Window by using Username as "USER" and Password as "PASSWORD"
Then login must be successful.
    
执行自动化测试后,会创建一个表作为自动化测试的结果。该表用于标签。

结果表如下表所示:

Cucumber测试中的Feature文件

具有多个场景的Feature文件

Feature文件可以包含多个场景或场景大纲。我们可以在一个Feature文件中写出一个特定特征的所有可能场景。
Cucumber中的Feature文件测试
通过使用关键字"场景"或"场景大纲",可以将一个场景与另一个场景分开。
然而,单个Feature文件可以包含任意数量的场景,但只关注一次注册、登录等一项功能。因此,最好将与特定功能相关的场景保存在单个Feature文件中。
场景可以并行执行,也可以在一组中一起执行。为了更清楚,让我们举一个例子:

例子:

Feature文件 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
    
Feature文件 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
    

Feature文件中的注释

如果我们不需要一次执行特定的场景,那么我们可以对该场景进行注释。
在Eclipse中,要注释多行或使用块注释,首先选择所有要注释的行,然后按Ctrl +/。同样,要删除注释,我们需要按 Ctrl + \。其他 IDE 可能包含其他快捷方式来执行此操作。
在评论任何场景时,不要忘记评论整个场景。否则,未注释的剩余场景行将被视为前一个场景的一部分。

如何创建功能Feature文件文件

在不同的IDE中创建Feature文件的方法有多种,这里我们在Eclipse IDE中创建。
我们可以创建一个扩展名为".feature"的特征文件。
以下是创建特征的步骤使用eclipse IDE:
1.为了在 Eclipse 中创建特征文件,请转到窗口左侧的文件选项,然后选择新建。
单击时New,您将获得以下三个选项:
项目 示例 其他
从这三个选项中选择其他选项。

考虑下图:

如何创建特征文件
2.选择其他选项后​​,您会看到几个选项,从这些选项中,选择常规文件选项,然后点击下一步。

考虑下图:

How创建特征文件
3、点击下一步后,选择要在其中创建Feature文件的项目。
选择项目后,您可以通过命名和".feature" 扩展名。您可以根据自己的选择为特征文件提供任何名称。提供名称后,单击完成按钮。

考虑下图:

如何创建特征文件
4.现在,创建的特征文件将出现在项目中。

考虑下图:

如何创建特征文件
生成的特征文件将类似于上图。在其中,我们可以编写待测试的 Web 应用程序的特性、场景和特性描述。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4