是否可以根据使用(或不使用)的标签在 Cucumber 步骤中执行不同的操作? [英] Is it possible to perform different actions in a Cucumber step based on the tag used (or not)?

查看:10
本文介绍了是否可以根据使用(或不使用)的标签在 Cucumber 步骤中执行不同的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在整个黄瓜测试中使用相同的步骤.我想根据调用功能是否分配了标签(在本例中为@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?)

伪代码来解释我在追求什么

Pseudo code to explain what I'm after

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

这篇关于是否可以根据使用(或不使用)的标签在 Cucumber 步骤中执行不同的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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