0

我正在尝试在 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 的方法。有什么帮助吗?

4

1 回答 1

1

I think your spec may be better worded as

Scenario: Checking Remember me
    Given I have logged in before and selected remember me
    When I visit "some protected web page"
    Then I should be logged in

The Given can set state for remember me, and perhaps the context for this can help you isolate the need to reset the session?

The above is also easier to read for laypeople and developers alike

于 2013-02-01T18:03:03.113 回答