2016-11-08 68 views
0

我是一名新程序員。我正在設置一個cucumber.io套件。我閱讀文檔並從https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md開始設置示例。當我運行提供的測試時,示例測試通過,如預期。當他們應該通過或失敗時,顯示爲「正在等待」的Cucumber-js測試

方案:閱讀文檔

✔鑑於我對Cucumber.js GitHub的倉庫

✔當我點擊 「CLI」

✔然後我會看到 「運行特定功能」

1情形(1通過)

3個步驟(3通過)

0m03.724s

以示例爲起點,當我添加另一個.feature和.js文件並運行測試時,我的新測試的所有操作都顯示爲「掛起」。另外,第一測試不再通過:

3方案(1曖昧,2未定義)

10步驟(2曖昧,7未定義,1通過)

0m03.743s

能任何人都告訴我我需要做什麼才能讓我的測試運行?我需要做些什麼來消除模糊和未定義的測試?

我檢查了我的正則表達式,它匹配。我知道我的縮進不在這裏,但我是發佈代碼的新手!

我.feature文件:

Feature: Sign In 
As a returning user of examples 
I want to log in the site 
So that I can use the site 

Scenario: Getting to the Sign in page via "Log In" 
    Given I am on example.com 
    When I click the "Sign In" button 
    Then I am taken to the login screen 

Scenario: Entering my information 
    Given I am on the login and I am the landing tab "Log In" 
    When I enter my credentials 
    And click the arrow 
    Then I am successfully logged in 

我的測試:

var seleniumWebdriver = require('selenium-webdriver'); 
module.exports = function() { 
this.Given(/^I am on I am on example.com$/, function() { 
    return this.driver.get('https://example.com'); 
}); 

this.When(/^I click on "([^"]*)"$/, function (text) { 
    return this.driver.findElement({linkText: text}).then(function(element) { 
    return element.click(); 
    }); 
}); 

this.Then(/^I should see "([^"]*)"$/, function (text) { 
    var xpath = "//*[contains(text(),'" + text + "')]"; 
    var condition = seleniumWebdriver.until.elementLocated({xpath: xpath}); 
    return this.driver.wait(condition, 5000); 
    }); 
}; 

回答

0

原始方案 -

Scenario: 
Given I am on the Cucumber.js GitHub repository - PASSED - This is the only step that passes that is present only in the original feature file. 
When I click on "CLI" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created. 
Then I should see "Running specific features" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created. 

新方案 -

Scenario: Getting to the Sign in page via "Log In" 
    Given I am on example.com - UNDEFINED - The step definition you have defined mentions 'I am on' twice instead of once. 
    When I click the "Sign In" button - UNDEFINED - No matching step. 
    Then I am taken to the login screen - UNDEFINED - No matching step. 

Scenario: Entering my information 
    Given I am on the login and I am the landing tab "Log In" - UNDEFINED - No matching step. 
    When I enter my credentials - UNDEFINED - No matching step. 
    And click the arrow - UNDEFINED - No matching step. 
    Then I am successfully logged in - UNDEFINED - No matching step. 

因此,你得到7個未定義,2個不明確和1個傳遞步驟。所以第一個原始場景變得模糊不清,另外兩個未定義。

您需要從新的test.js中刪除重複的步驟,並添加新的步驟定義以匹配新的方案步驟。

+0

非常感謝你幫助我理解這一點。 @Grasshopper,當你說「你定義的步驟定義提到'我已經'兩次了'你能告訴我在哪裏?是否因爲該步驟在兩個功能文件中?我的許多功能將涉及訪問同一網站 - 我如何區分每一步? – Laurie

+0

this.Given(/ ^我在我上example.com $ /,函數() - 這是來自你在問題中共享的文件,你看到'我在'在這個模式中重複兩次。將不匹配你已經定義了第二種情況的步驟,只是嘗試爲每個步驟編寫單獨的步驟定義,然後看看你是否可以使用模式來減少常見步驟 – Grasshopper

+0

謝謝@grasshopper我甚至沒有看到我犯了這個錯字。我認爲我現在開始瞭解更多。謝謝! – Laurie

相關問題