2

多个场景是否可以使用同一个示例表?

所以而不是像下面这样:

Scenario Outline: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario Outline: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

我可以做类似的事情

Scenario Outline: Reusable Example
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"

  Scenario: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"

我在 StackOverflow 上发现了一个类似的问题,但是在一个场景中合并我的所有场景对我来说不是一个选择。由于这个问题是在 2014 年发布的,也许框架中有一些我不知道的进步:D

先感谢您。

4

2 回答 2

2

您可以使用qaf-gherkin,您可以在其中移动外部文件中的示例并将其用于一个或多个场景。使用 qaf,您的功能文件可能如下所示:

Scenario Outline: First Scenario
   Given I am viewing "<url>"
   Then I assert that the current URL "<url>"
   Examples:{'datafile':'resources/testdata.txt'}

Scenario Outline: Second Scenario
Given I am viewing "<url>" with route "</contactus>"
Then I assert that "<url>" contains "contactus"
Examples:{'datafile':'resources/testdata.txt'}

您的数据文件将如下所示:

url
https://google.com
https://twitter.com

这是参考

于 2018-09-06T00:26:12.163 回答
0

您可以使用背景来指定对于所有场景都相同的步骤。(查看约束的链接)

功能文件可能看起来像

Feature: use of reusable Given

  Background: Reusable Example
    Given I am viewing url
      | https://google.com |
    And a search phrase is entered in the search field

  Scenario: First Scenario
    And step for first scenario

  Scenario: Second Scenario
    And step for second scenario

实现胶水代码Given

@Given("^I am viewing url$")
public void iAmViewing(List<String> url) throws Throwable {
    System.out.println("url = " + url);
}

编辑问题更新后Scenario Outline,这两个示例都可以使用。

Feature: use of example

  Scenario Outline: First Scenario
    Given I am viewing "<host>" with path "<path>"
    Then I assert that the current URL is "<host><path>"

    Examples:
      | host                | path       |
      | https://google.com  | /          |
      | https://twitter.com | /contactus |
于 2018-09-05T09:08:27.513 回答