2013-08-01 81 views
1

我實現貝哈特有水貂,採用以下特點:貝哈特與水貂意外一步錯誤

Scenario: Search for another phrase that exists 
Given I am on "/wiki/Main_Page" 
When I fill in "search" with "Behavior Driven Development" 
And I press "searchButton" 
Then I should see "agile software development" 

我已經使用了GOUTTE和SAHI公司,誤差是一致的。我得到錯誤的「那我應該看到‘敏捷軟件開發’

Scenario: Search for another phrase that exists    # features/wikipedia.feature:13 
Given I am on "/wiki/Main_Page"       # WikipediaFeatureContext::visit() 
When I fill in "search" with "Behavior Driven Development" # WikipediaFeatureContext::fillField() 
And I press "searchButton"         # WikipediaFeatureContext::pressButton() 
Then I should see "agile software development" 
    Ambiguous match of "I should see "agile software development"": 
    to `/^I should see "([^"]*)"$/` from AccountFeatureContext::iShouldSee() 
    to `/^(?:|I)should see "(?P<text>(?:[^"]|\\")*)"$/` from WikipediaFeatureContext::assertPageContainsText() 

如何來解決這個問題。

回答

1

刪除了‘我’從此我應該能看到‘敏捷軟件開發’的步驟。

0

這個問題也可以通過使正則表達式更加明確予以避免。

你上面仍然可以讓你寫曖昧步驟中使用的方法。

最好。

1

您的小黃瓜語句匹配多個方法的正則表達式。

您的FeatureContext文件中可能有另一種方法,它會匹配導致模糊錯誤的「我應該看到」。

我發現,當我遇到這個時,我錯誤地拼寫應該與大寫字母S結果在一個新的方法被追加。

「我應該看到‘等等等等’」 代替 「我應該能看到‘等等等等’」

請檢查您的特性文件中的任何拼寫錯誤:「我看到...」語句和檢查功能上下文文件並刪除額外的方法。

然後您就可以寫小黃瓜語法的語句正確包括你我的

1

你包括定義/ 2分不同的情況下實現「相同」的步驟定義。在我看「東西」步驟定義來自於MinkContext免費的,所以我的建議是從您的自定義背景移除:AccountFeatureContext和WikipediaFeatureContext和包括MinkContext:

http://behat.org/en/latest/user_guide/context.html#multiple-contexts

如果你把額外的邏輯在你的方法定義,我建議創建一個新的一句話來說明你是假裝什麼可看,那裏使用的子上下文重用現有的實現:

http://docs.behat.org/en/v2.5/guides/4.context.html

除了這個考慮使用anothe r驅動程序與Sahi不同,它不再保持:

https://packagist.org/packages/behat/mink-sahi-driver