我正在尝试在 Symfony2 项目中使用 Behat 和 Mink 测试记住我的功能。但是,我的方法不起作用。
我尝试了以下方法:
#behat.yml
Scenario: Checking Remember me
Given I am on "/"
When I fill in "username" with "john"
And I fill in "password" with "john"
And I check "remember_me"
And I press "Login"
Then I should be logged in
When I restart the browser
Then I should be logged in
Scenario: Not Checking Remember me
Given I am on "/"
When I fill in "username" with "john"
And I fill in "password" with "john"
And I press "Login"
Then I should be logged in
When I restart the browser
Then I should be logged out
我的特征上下文包含(除其他外)以下方法:
#FeatureContext.php
/**
* @Then /^I should be logged in$/
*/
public function iShouldBeLoggedIn()
{
$this->assertElementOnPage('.user-area');
}
/**
* @Given /^I should be logged out$/
*/
public function iShouldBeLoggedOut()
{
$this->assertElementNotOnPage('.user-area');
}
/**
* @When /^I restart the browser$/
*/
public function iRestartTheBrowser()
{
$driver = $this->getSession()->getDriver();
$session = new Session($driver);
$session->start();
$session->visit('/');
}
问题出在iRestartTheBrowser()
. 这没有做它应该做的事情。我正在寻找一种清除会话数据但保留 cookie 的方法。有什么帮助吗?