我有以下情况:
@mink:selenium2
Scenario: Login
Given there are the following users:
| username | password | email |
| admin | 1234 | <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="79181d141017390a161a1018151a180b571a1614" rel="noreferrer noopener nofollow">[email protected]</a> |
When I am on "/login"
And I fill in "username" with "admin"
And I fill in "password" with "1234"
And I press "Login"
Then I should be on "/admin"
所以我想有一个 cleanupUsers 作为 @AfterScenario ,我可以清理场景中插入的任何内容。那么如何访问用户的TableNode呢?
最佳答案
您可以将您的用户保存在私有(private)属性(property)中,以便您稍后可以在 a hook 中访问它们:
private $users;
/**
* @Given there are the following users:
*/
public function thereAreFollowingUsers(TableNode $table)
{
$this->users = $table;
// ...
}
/**
* @AfterScenario
*/
public function cleanupUsers(AfterScenarioScope $scope)
{
if (null !== $this->users) {
// do the cleanups
// ...
// reset the property
$this->users = null;
}
}
关于php - Behat:如何清理场景中创建的数据库记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32456579/