我在整个黄瓜测试过程中使用了相同的步骤。我想根据调用功能是否分配了标记(在本例中为@javascript)进行微小更改。
是否可以在步骤中测试标签的存在和名称以更改行为? (我意识到我可以创建不同的步骤,但这不是很干吗?)
伪代码解释我在追求什么
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
答案 0 :(得分:5)
我通过使用钩子设置变量来解决这个问题,如果您的标记与驱动程序没有关联,这可能很有用:
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
答案 1 :(得分:3)
我认为你不能轻易地从步骤defs中直接访问标签,但你可以访问当前的驱动程序:
Capybara.current_driver
因此,假设您为@javascript标记的方案使用了不同的驱动程序,这应该可以。