是否可以根据使用(或不使用)的标签在 Cucumber 步骤中执行不同的操作?

2023-12-21

在我的黄瓜测试过程中,我在不同的位置使用相同的步骤。我想根据调用功能是否分配了标签(在本例中为@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

我通过使用钩子设置变量来解决这个问题,如果您的标签未与驱动程序关联,这可能很有用:

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以根据使用(或不使用)的标签在 Cucumber 步骤中执行不同的操作? 的相关文章

随机推荐