我可以在黄瓜中使用背景和示例吗? [英] Can I use background with examples in cucumber?

查看:14
本文介绍了我可以在黄瓜中使用背景和示例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个所有场景的第一步的例子.但是所有场景的第一步都是一样的,只有一个元素不同.所以我想在后台进行所有这一步,并想添加带有背景的示例.简而言之,假设我想导航到 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.

这篇关于我可以在黄瓜中使用背景和示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆