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

2023-09-08 00:14:35 作者:无恙

我想通过一个所有场景的第一步的例子.但是所有场景的第一步都是一样的,只有一个元素不同.所以我想在后台进行所有这一步,并想添加带有背景的示例.简而言之,假设我想导航到 facebook、twitter、google 和 youtube 页面并单击一个元素.我可以用下面的东西吗?

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: ...

推荐答案

你应该可以用下面的数据表来实现后台 -

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

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

这样做的方法可能很少,其中之一是检查您的场景名称,并根据该名称从要加载的网页的数据表中找到相应的值.

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.