2013-10-03 70 views
0

我目前正在一個小項目上工作,並且我決定和Behat/Mink一起玩耍,我遇到了我無法單獨解決的第一個問題。如何斷言一個文本只存在貂皮1次

我有這樣的功能,它按預期工作

Scenario: Create Customer 
    Given I am on "/login" 
    When I fill in "username" with "testuser" 
    And I fill in "password" with "123" 
    And I press "Login" 
    And I follow "Customers" 
    And I follow "Create" 
    Then I should be on "/customer/new" 
    And I fill in "email" with "[email protected]" 
    And I press "Save" 
    Then I should be on "/customer/" 
    And I should see "[email protected]" 

,當我在「保存」項目,然後按下檢查,如果電子郵件已經存在。如果是這樣,它只是重定向到/客戶。我怎麼能斷言,一個文本只有一次(不是兩次或更多)在我的網頁上?

回答

3

你可以寫一個新的臺階,喜歡的東西:

/** 
    * @Then /^I should see "([^"]*)" exactly "([^"]*)" times$/ 
    */ 
public function iShouldSeeTextSoManyTimes($sText, $iExpected) 
{ 
    $sContent = $this->getSession()->getPage()->getText(); 
    $iFound = substr_count($sContent, $sText); 
    if ($iExpected != $iFound) { 
     throw new \Exception('Found '.$iFound.' occurences of "'.$sText.'" when expecting '.$iExpected); 
    } 
} 

,然後有一個場景,如:

Scenario: Some many times 
Given I am on "http://en.wikipedia.org" 
Then I should see "Welcome" exactly "1" times 
相關問題