Reusable/Generic 黄瓜中的示例 table
Reusable/Generic Examples table in Cucumber
是否可以多个场景使用相同的例子table?
所以不要像下面这样:
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 Whosebug,但是将我的所有场景合并到一个场景中对我来说不是一个选择。由于这个问题是在 2014 年发布的,也许框架中有一些我不知道的进步:D
提前谢谢你。
您可以使用 Background 来指定对所有场景都相同的步骤。 (查看 link 的约束)
功能文件可能看起来像
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);
}
edit 更新问题后,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 |
您可以使用 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.
是否可以多个场景使用相同的例子table?
所以不要像下面这样:
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 Whosebug,但是将我的所有场景合并到一个场景中对我来说不是一个选择。由于这个问题是在 2014 年发布的,也许框架中有一些我不知道的进步:D
提前谢谢你。
您可以使用 Background 来指定对所有场景都相同的步骤。 (查看 link 的约束)
功能文件可能看起来像
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);
}
edit 更新问题后,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 |
您可以使用 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.