I am trying to test a remember me functionality with Behat and Mink in a Symfony2 project. However, my approach is not working.
I tried the following:
#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
My feature context contains (among others) the following methods:
#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('/');
}
The problem lies within iRestartTheBrowser(). This is not doing what it is supposed to do. I am looking for a way to clear session data but keep cookies. Any help?