2017-02-12 51 views
0

我有一個黃瓜功能像這樣的:如何在多個文件上運行一個Cucumber(使用量角器)場景?

@MainSuite 
Scenario: Verify that user can login 
    Given I can see the login form 
    Then I set a username 
    And I set a password 
    And I click in Login button 
    Then I see the "wrong-password" message 

我需要檢查用戶可以在5個不同的頁面登錄。 我需要在5個不同的地方運行該功能。 這就像我需要在/login.html,/old_login.html,/after_restore_password.html和更多內容中運行該功能(這只是一個示例)。

你知道該怎麼做嗎?

目前,我只有一個文件硬編碼。顯然我需要改變它。

this.Given(/^I can see the login form$/, function(done) { 
    this.goTo('login.html'); 
    browser.wait(EC.visibilityOf(this.loginFormContainer)); 
    done(); 
}); 

回答

0

創建一個包含您可以轉到的不同登錄頁面的對象。

如果需要執行任何額外的代碼,請在步驟def中包含if語句。

this.Given(/^I can see the "(.*)" login form$/, function(loginPage, done) { 
    var logins = { 
     login : "login.html", 
     afterpasswordreset: "after-password-reset.html" 
    } 
    loginPage = loginPage.toLowerCase().replace(" ", ""); 
    this.goTo(logins[loginPage]); 
    browser.wait(EC.visibilityOf(this.loginFormContainer)); 
    done(); 
}); 

讓無論是單獨的方案或爲每個登錄的變化特徵文件,或者簡單地爲他們創造

編輯

這裏是我會怎麼實現的場景勾勒出一個方案概述:

@MainSuite 
Scenario Outline: Verify that user can login 
    Given I can see the "<loginType>" login form 
    And I set a username 
    And I set a password 
    When I click in Login button 
    Then I see the "wrong-password" message 

Examples: 
    | loginType    | 
    | Login     | 
    | After Password Reset | 
+0

Nop。您將有2次執行給定規則,但每個下一行只有一個(當時和之後) –

+0

您是什麼意思?給定時間然後並不總是必須在三組中。這本身就是一種誤解。它必須具有足夠的描述性,這就是爲什麼「And」和「But」語法規則到位的原因。 –

+0

檢查我在主要問題中寫的情景。你如何寫你的建議黃瓜escenario? (用這個例子編輯你的答案,你會發現有問題。) –

相關問題