Gherkin语言 Cucumber 中标签是什么? Cucumber 测试的特点 Gherkin Language 正如我们在 Cucumber 测试中了解到的,feature-file是用可执行的测试脚本创建的。编写这些可执行测试脚本的语言称为 Gherkin 语言。 基本上,Gherkin 是一种用于解释和执行测试脚本的纯英文文本语言。 当 Cucumber 支持英文文本时,为什么我们需要单独的 Gherkin 语言? 已经多次讨论过 Cucumber 支持纯英文文本,那么为什么我们需要一个单独的 Gherkin 语言。这个问题的答案在于BDD(行为驱动开发)的概念。 众所周知,BDD 在准备测试脚本时涉及各种软件行为开发可能性。这些可以是与开发相关的可能性或与业务相关的可能性。为了实现这些可能性,我们在开发测试脚本时需要来自不同社区的成员,如测试人员、开发人员、产品所有者和项目经理。 由于这些成员不属于同一个社区;因此,几乎不可能每个人都使用共同语言。因此,测试脚本的概念处于高风险中。为了降低这种风险,开发了Cucumber。 Gherkin 在纯英文文本中提供了一组通用的关键字,可供来自不同社区的成员使用,并且可以从测试脚本中获得相同的输出。 Gherkin 提供了以下特定关键字来编写功能文件中的常见测试脚本: Feature Scenario Given When Then But And Background Feature Cucumber 测试的每个特征文件都以一个特征关键字开头。它是要测试的独立单元或功能。例如,登录功能、支付转账功能、注册功能等。 例子: Feature: Login Scenario: Login verification Given user navigates to the website javatpoint.com And user logs in through Login Window by using Username as "USER" and Password as "PASSWORD" Then login must be successful. Scenario 每个功能都包含测试功能所需的测试次数。每个测试都被命名为一个场景。 例如,功能登录功能可以包含两个场景,第一个用于成功登录,第二个用于不成功登录。 Scenario: Successful Login with Valid entries Given user navigates to the website javatpoint.com And user logs in through Login Window by using Username as "USER" and Password as "PASSWORD" Then login must be successful. Scenario: Unsuccessful Login with Invalid entries Given user navigates to the website javatpoint.com And user logs in through Login Window by using Username as "USER" and Password as "1234erty" But user entered wrong username and password Then login must be unsuccessful. Given 这个关键字是指测试的前提条件。例如,要访问任何 Web 应用程序,第一个要求或前提是导航其主页,因为我们可以从主页导航到其他链接,例如signup、login等。 例子: Feature: Login Scenario: Login verification Given user navigates to the website javatpoint.com And user logs in through Login Window by using Username as "USER" and Password as "PASSWORD" Then login must be successful. When 它通常指的是用户要执行的操作。 例子: Scenario: Successful Login with Valid entries Given user navigates to the website javatpoint.com When User Navigate to Login Page And user logs in through Login Window by using Username as "USER" and Password as "PASSWORD" Then login must be successful. 当用户用“ *nikita.sharma27@gmail.com* ”填写“注册电子邮件文本框”时。 Then 此关键字指的是上一步或即将进行的操作的结果。 例子: Scenario: Successful Login with Valid entries Given user navigates to the website javatpoint.com When User Navigate to Login Page And user logs in through Login Window by using Username as "USER" and Password as "PASSWORD" Then login must be successful. But 此关键字用于添加否定条件。 例子: Scenario: Unsuccessful Login with Invalid entries Given user navigates to the website javatpoint.com And user logs in through Login Window by using Username as "USER" and Password as "1234erty" But user entered wrong password Then login must be unsuccessful. And 此关键字用于在您的步骤中添加更多条件。 例子: Given User is on Home Page And Login Link is displayed When User Navigates to Login form And User enters email and Password Then Login Successfully will be displayed And Logout Link should be displayed 背景 此关键字用于定义功能文件中所有测试通用的步骤。例如,导航到主页、点击登录、输入用户名和密码、点击提交按钮是几乎所有Web应用程序中的常见步骤。 Cucumber 中标签是什么? Cucumber 测试的特点