代码之家  ›  专栏  ›  技术社区  ›  srboisvert

如何使用Cucumber测试designe的可记忆功能?

  •  7
  • srboisvert  · 技术社区  · 16 年前

    我想有一个黄瓜功能测试的记忆功能设计(记得我饼干)。

    使用水豚很容易勾选“记住我”复选框,但是我应该如何模拟用户在关闭窗口后返回站点?

    5 回复  |  直到 16 年前
        1
  •  1
  •   nruth    16 年前

    我提出了下面的框架测试方法,并且稍微简化了seleniumapi的使用,以测试cucumber/capybara中的“记住我”功能。它只是告诉驱动程序手动删除会话cookie。并非所有驱动程序都受支持,我只实现了我使用的两个驱动程序:

    http://gist.github.com/484787

    这假设会话的cookie存储。从场景中删除@announce标记以消除冗长的内容。

    the mailing list discussion ,可能正在查看其他cookie存储,并通过查询或文件删除来删除它们:

    摘自敏捷轨道手册:

    config.action_controller.session_store = CGI::Session::PStore (or just :p_store)
    config.action_controller.session_options[:tmpdir] = "/Users/dave/tmp" 
    config.action_controller.session_options[:prefix] = "myapp_session_"
    

    rake db:sessions:create
    config.action_controller.session_store = :active_record_store
    

    希望这有帮助,

    尼克

        2
  •  1
  •   jim    15 年前

    nruth的要点真的很有帮助,但我觉得删除cookie的名字是欺骗。我创建了一个步骤,删除浏览器在关闭并重新启动时将删除的cookie(任何没有设置到期日期的cookie)。

    你可以在照片里看到 this commit (虽然我只为RackTest驱动程序做了这个,因为我没有Selenium设置)。您还可以在中看到“我的登录/记住我”功能 this commit this commit .

    我希望这会有帮助。

        3
  •  0
  •   Jonathan    16 年前

    email-spec 为了达到这个目的。我的场景如下所示:

    @allow-rescue
    Scenario: Create New Account (Everything cool)
    Given I am not authenticated
    When I go to register
    And I fill in "Name" with "bill"
    And I fill in "Email" with "bill@example.com"
    And I fill in "Password" with "please"
    And I fill in "Password Confirmation" with "please"
    And I press "Sign up"
    Then "bill@example.com" should receive an email
    And I open the email
    And I should see "Confirm my account" in the email body
    When I follow "Confirm my account" in the email
    Then I should see "Your account was successfully confirmed. You are now signed in."
    

    注意 @允许救援

    希望这有帮助。

        4
  •  0
  •   Jed Schneider    16 年前

    Given I am on the login screen
    And I select 'Remember Me'
    And I click 'login'
    Then I should be 'logged in'
    When I click 'log out'
    Then I should be 'logged out' #=> potentially destroy a session here?
    When I click log in
    Then I should be logged in
    And I should not be directed to the login form.
    

    这个 使用cabybara的当前cookie状态对此流进行建模。

        5
  •  0
  •   Cu1ture    11 年前

    你可以用 show_me_the_cookies

    And(/^I leave the site$/) do
      expire_cookies
    end