2013-12-18 30 views
0

在下面的功能中,我檢查是否存在特定的工作類型(合同),如果發現則執行其他操作,否則跳過其餘步驟。當跳過時,將場景標記爲合格(技術上它不是合格,也不是失敗或未決) 如何在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| 

回答

1

骯髒的方法:在步驟「如果有合同的工作」

@jobs = false 
@jobs = true If contract_jobs 
在下面的步驟

然後,說「它應該有一個小時[R吃」

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