首页 文章

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

提问于
浏览
0

在下面的功能中,我正在检查是否存在特定的工作类型( Contract ),如果发现则执行某些操作,否则将跳过其余步骤 . 当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 回答

  • 1

    肮脏的方式:步骤'如果有 Contract 工作'

    @jobs = false
    @jobs = true If contract_jobs
    

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

    if @jobs
     <your other assertions>
    else
     true
    end
    

    只是在步骤定义中设置为true会使步骤通过(实际上任何非断言语句都可以) . 虽然我不建议 Build 这样的场景(可以说,条件有用的场景/黄瓜风格) . 就个人而言,我会把它分成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
    
  • 1

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

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

相关问题