如何跳过步骤定义或将场景标记为已通过?

时间:2013-12-18 12:53:12

标签: java ruby cucumber cucumber-jvm

在下面的功能中,我正在检查是否存在特定的工作类型(合同),如果发现则执行某些操作,否则将跳过其余步骤。当skippedm时,将场景标记为已通过(从技术上讲,它不是通过,也不是失败或待处理) 我怎么用黄瓜或黄瓜-jvm呢?

Feature: View job types
  Users can view job type from front page and from side menu

  Scenario Outline: View job type from front page

    Given I login as "<user>"
    And if there are contract jobs
    Then it should have a hourly rate
    And the daily rate in "USD" with "2" decimal places

    Examples:
    | user |
    | hello|
    | world|

2 个答案:

答案 0 :(得分:1)

看看黄瓜'钩子'https://github.com/cucumber/cucumber/wiki/Hooks

另外,要跳过步骤,尽管没有条件(至少据我所知),你可以在黄瓜步骤前使用@ignore标签

答案 1 :(得分:1)

肮脏的方式:在步骤'如果有合同工作'

@jobs = false
@jobs = true If contract_jobs

然后在接下来的步骤中,说'它应该有小时费率'

if @jobs
 <your other assertions>
else
 true
end

在步骤定义中设置true会使步骤通过(实际上任何非断言语句都可以)。虽然我不建议建立这样的场景(可以说,条件有用的场景/黄瓜风格)。就个人而言,我会把它分成2个 - 积极情景:

Given I login as "<user>"
Then there are contract jobs
And the job has an hourly rate
And the job has a daily rate in "USD" with "2" decimal places

和消极情景

Given I login as "<user>" (a profile for which you know there won't be contract jobs)
Then there are no contract jobs