我可以在黄瓜中使用背景示例吗?

问题描述 投票:0回答:2

我想通过所有场景的第一步传递示例。但是在所有场景中的第一步是相同的,只有一个元素是不同的。所以我想在后台完成所有这一步,并希望添加背景示例。简而言之,我想导航到facebook,twitter,google和youtube页面并单击一个元素。我可以使用以下的东西吗?

Background: Open the web-page
Given Open the <web_page> website
Examples:
|web_page|
|facebook|
|twitter|
|google|
|youtube|

Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
cucumber
2个回答
0
投票

这看起来很奇怪,但是如果你使用gherkin with qaf,你可以得到如下:

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|

使用qaf,您还可以使用external data-source外部特征文件,例如:

Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}

Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}

Scenario: ...
Examples:Examples: {"dataFile":"resources/data/sitedata.csv"}

使用BDD2 syntax,您可以拥有以下内容:

@dataFile:resources/data/sitedata.csv
Background: Open the web-page
    Given Open the <web_page> website

Scenario: ...

Scenario: ...

Scenario: ...

0
投票

您将能够使用数据表实现背景,如下所示 -

Background: Open the web-page 
Given Open the <web_page> website
|web_page| 
|facebook| 
|twitter| 
|google| 
|youtube|

如何将正确的网页值从数据表传递给步骤实现方法?

这样做的方法很少,其中一个方法应检查您的方案名称,并根据要从要加载的网页的数据表中找到相应的值。

© www.soinside.com 2019 - 2024. All rights reserved.