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

当我按下“保存”时,项目会检查电子邮件是否已经存在。如果是这样,它只会重定向到 /customer。我如何断言我的页面上只有一次(不是两次或更多)文本?

4

1 回答 1

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
于 2013-10-04T11:41:31.523 回答