【问题标题】:How to use data table in background in cucumber黄瓜如何在后台使用数据表
【发布时间】:2019-12-10 09:15:10
【问题描述】:

我想对几个测试用例执行通用步骤。以下是通用步骤。但是在后台,由于我无法使用 Scenario Outline,有什么替代方法?

Background:To test employee id search 

Scenario Outline: 
Given I am on login Screen
When I enter credentials "<User_ID>" and "<Password>"
When I clicks on search button
And search by "<Employee_id>"

Examples:
|User_ID|Password  |Employee_id|
|Admin  |Password  | Q58ewQ    |

【问题讨论】:

  • 背景不能绑定到场景大纲。背景是其他场景和场景大纲的前提条件

标签: selenium cucumber


【解决方案1】:

场景大纲是一种在编写一个场景的同时运行多个场景的方法。背景是在每个场景之前运行的一组步骤。你不能把轮廓放在背景中,这是没有意义的。

【讨论】:

  • 是的,我知道我们不能在背景中使用硒轮廓。但只是想知道有什么替代方法
【解决方案2】:

Background 用于将在功能文件中的每个场景(或示例)之前运行的步骤。

每个Scenario Outline 将作为单独的Scenario / Example 运行。

您不能在内部背景中使用场景大纲,因为那没有任何意义。

请查看文档链接以获取更多信息。

【讨论】:

  • 在这种情况下,您需要为每个场景/示例添加从背景到场景大纲的步骤
【解决方案3】:

这是一个非常必要的例子,BDD 需要是声明性的。 Best Pratices BDD

为什么要创建一种登录方法。

Login(username, password){
  set username = username;
  set password = password;
  clickButton;
}

并创建一个步骤。

Given the user logged on the system
  login(username, password)

这是您在背景中使用的步骤。

【讨论】:

  • 您是否建议我在属性文件中包含登录凭据和其他详细信息?
【解决方案4】:

您可以在Cucumber Background 中使用Data Table

Background:
    Given User is on Home Page
    When User Navigate to LogIn Page
    And User enters Credentials to LogIn
    | testuser_1 | Test@153 |

【讨论】:

    【解决方案5】:

    您可以在 Cucumber Background 中使用表格:

    Background:
        Given I open Google's search page
        When I use the following keywords to search in the Google's search page:
           | CucumberBDD    | 
           | CucumberHooks  | 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多