多个场景是否可以使用相同的Examples表?
所以不要像下面那样:
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"
我发现了一个similar question on StackOverflow,但在一个场景中合并我的所有场景对我来说都不是一个选择。由于这个问题是在2014年发布的,可能在框架中有一些我不知道的进步:D
先感谢您。
您可以使用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
这是reference。
您可以使用Background指定所有方案相同的步骤。 (看一下约束的链接)
功能文件可能看起来像
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 |