Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate closing/reopening the browser in cucumber/capybara?

I'm writing cucumber tests to test user 'Remember me' type functionality, and in order to do that in real life the user would close their browser, reopen their browser, and come back to the site.

My test so far looks like this:

Scenario: 'Remember me' checked
  Given I have checked "Remember me"
  And I am logged in as "[email protected]"
  When I close and re-open my browser
  And I come back to the dashboard
  Then I should be on the dashboard

However I don't know what to fill in for the 'When I close and re-open the browser' step definition.

Does anyone know how I would do this (or if this isn't what I should be doing, how I should be testing it?)

like image 256
sevenseacat Avatar asked Sep 11 '11 07:09

sevenseacat


1 Answers

I use Show me the cookies.

Add to bundle with gem 'show_me_the_cookies' and then add World(ShowMeTheCookies) in your features/support/env.rb

Then just define a step:

When /^I reopen the browser$/ do
  expire_cookies
  visit [ current_path, page.driver.request.env['QUERY_STRING'] ].reject(&:blank?).join('?')
end
like image 197
Mohammad El-Abid Avatar answered Sep 24 '22 00:09

Mohammad El-Abid