Question

Im currently working on a small project and i decided to play around with Behat/Mink a little and i came across my first problem i can not solve alone.

I have this feature and it is working as expected

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 "test@test.de"
  And   I press "Save"
  Then  I should be on "/customer/"
  And   I should see "test@test.de"

When i press on "Save" the project then checks, if the email already exists. If it does it just redirects to /customer. How can i assert, that a text is only once (not twice or more) on my page?

Was it helpful?

Solution

You could write a new step, something like :

/**
  * @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);
    }
}

And then have a scenario such as :

Scenario: Some many times
Given I am on "http://en.wikipedia.org"
Then I should see "Welcome" exactly "1" times
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top