0

在下面的功能中,我正在检查是否存在特定的工作类型(合同),如果发现则执行某些操作,否则跳过其余步骤。当 skippedm 时,将场景标记为通过(从技术上讲,它不是通过,也不是失败或待处理)我如何在 cucumber 或 cucumber-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|
4

2 回答 2

1

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

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

于 2013-12-18T14:59:01.620 回答
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
于 2014-01-03T17:29:03.170 回答