【问题标题】:Testing Remember me functionality with Behat/Mink使用 Behat/Mink 测试记住我的功能
【发布时间】:2013-02-02 02:03:03
【问题描述】:

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

【问题讨论】:

  • 顺便说一句,我尝试的第一件事当然是重置或重新启动会话。没用,因为 cookie 也被删除了。

标签: behat mink


【解决方案1】:

我认为您的规范可能会更好地表述为

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

Given 可以为 记住我 设置状态,也许这方面的上下文可以帮助您隔离重置会话​​的需要?

以上内容对于外行和开发人员来说也更容易阅读

【讨论】:

  • 给你的好食物,谢谢。我是 Behat 的新手,我仍然在弄清楚我应该在多大程度上描述单个工作流程,以及我应该在多大程度上牢记功能测试。我会试一试的。
猜你喜欢
  • 1970-01-01
  • 2012-10-12
  • 2017-02-09
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多