问题
I want to pass an example with first step of all scenarios. But first step in all scenarios are same, just one element is different. So I want to all that step in background and want to add examples with background. In short suppose I want to navigate to facebook, twitter, google and youtube page and click on one element. Can I use following thing for that??
Background: Open the web-page
Given Open the <web_page> website
Examples:
|web_page|
|facebook|
|twitter|
|google|
|youtube|
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
回答1:
This looks odd requirement, however if you are using gherkin with qaf you can have it as below:
Background: Open the web-page
Given Open the <web_page> website
Scenario: ...
Examples:
|web_page|
|facebook|
|twitter|
|google|
|youtube|
Scenario: ...
Examples:
|web_page|
|facebook|
|twitter|
|google|
|youtube|
Scenario: ...
Examples:
|web_page|
|facebook|
|twitter|
|google|
|youtube|
With qaf you can also use external data-source outside feature file, for example:
Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}
Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}
Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}
With BDD2 syntax you can have as below:
@dataFile:resources/data/sitedata.csv
Background: Open the web-page
Given Open the <web_page> website
Scenario: ...
Scenario: ...
Scenario: ...
回答2:
You shall be able to implement background with Data table as below -
Background: Open the web-page
Given Open the <web_page> website
|web_page|
|facebook|
|twitter|
|google|
|youtube|
How to pass correct value of web page from Data table to step implementation method ?
There could be few ways doing so and one of them shall be check your scenarios name and based on that find corresponding value from Data table of web page to be loaded.
来源:https://stackoverflow.com/questions/55425083/can-i-use-background-with-examples-in-cucumber