2013-10-03 3 views
0

현재 작은 프로젝트에서 일하고 있으며 Behat/Mink와 조금 놀기로 결심했습니다. 첫 번째 문제는 혼자 해결할 수 없었습니다.텍스트가 오직 존재한다고 단언하는 방법

나는이 기능이 있고 난 후 "저장"프로젝트에 대한 확인을 누르면 이메일이 이미 존재하는 경우,

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]" 

를 예상대로 작동합니다. 이 경우/customer로 리디렉션됩니다. 내 페이지에 텍스트가 한 번만 (두 번 이상이 아니라고) 주장 할 수 있습니까?

답변

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