Can I use background with examples in cucumber?

孤人 提交于 2019-12-20 06:24:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!