为Mink创建步骤

时间:2012-08-06 14:15:51

标签: behat mink

我是Mink,Behat等的新手,所以我需要帮助。

我有一个包含一些行的表,我想检查是否删除了一行。

在我的场景中,我有类似的事情:

When I press "Delete"
Then I should be on "/example_url/"
    And I should see "Object list"
    And the response should not contain "Value1" "Value2" "Value3" "Value4"

我是怎么做到的?我怎么做“响应不应该包含一行的某些值”?

我不知道Mink是否可行,或者我需要使用单一测试。

1 个答案:

答案 0 :(得分:1)

您可以在步骤中使用tables

And the result table should not contain:
  |Value |
  |Value1|
  |Value2|
  |Value3|
  |Value4|

Behat会将它作为TableNode实例传递给您的step方法:

/**
 * @Given /the result table should not contain:/
 */
public function thePeopleExist(TableNode $table)
{
    $hash = $table->getHash();
    foreach ($hash as $row) {
        // ...
    }
}

详细了解使用Gherkin语言编写功能:http://docs.behat.org/guides/1.gherkin.html

Digression :请注意,大部分时间在您的功能中直接使用Mink步骤并不是最好的主意,因为大部分时间它不是您的业务语言。如果你写了:

,你的场景将更具可读性和可维护性
When I press "Delete"
Then I should be on the user page
 And I should see a list of users
 And the following users should be deleted:
   |Name   |
   |Biruwon|
   |Kuba   |
   |Anna   |

在您的步骤实现中,您可以通过返回然后实例来使用默认的Mink步骤:

/**
 * @Given /^I should see a list of users$/
 */
public function iShouldSeeListOfUsers()
{
    return new Then('I should see "User list"');
}