是否可以在基于所使用(或不使用)标记的黄瓜步骤中执行不同的操作? [英] Is it possible to perform different actions in a Cucumber step based on the tag used (or not)?
本文介绍了是否可以在基于所使用(或不使用)标记的黄瓜步骤中执行不同的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在整个黄瓜测试中使用相同的步骤。我想根据调用的功能是否分配了标签(在这种情况下为@javascript)进行一些小的更改。
I use the same step in various placed throughout my cucumber testing. I would like to make a minor change based on whether or not the calling feature has a tag assigned (in this case @javascript).
可以测试在一个步骤中的标签的存在和名称来改变行为? (我意识到我可以创建不同的步骤,但是不是很干燥。)
Is it possible to test for the presence and name of a tag within a step to change the behaviour? (I realise I could just create different steps, but that's not very DRY is it?)
伪代码来解释我之后
When /^I sign in as "(.*)\/(.*)"$/ do |email,password|
step %{I go to the sign in page}
step %{I fill in "user_email" with "#{email}"}
step %{I fill in "user_password" with "#{password}"}
if tag && tag == "@javascript"
step %{I follow "LOG IN"}
else
step %{I press "LOG IN"}
end
end
推荐答案
我通过使用钩子来设置变量,如果您的代码未与驱动程序相关联,这可能很有用:
I got around this by using hooks to set variables, which may be useful if your tag isn't associated with a driver:
Before('@mobile') do
@mobile = true
end
When /^I go to the homepage$/ do
if @mobile
visit "m.mysite.com"
else
visit "www.mysite.com"
end
end
这篇关于是否可以在基于所使用(或不使用)标记的黄瓜步骤中执行不同的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文