0

I have the following in my scenario:

And I click the link Log out
Then I should see the login page

Clicking the Log out link sends the user to /log_out, which redirects back to the log in page. Webrat is failing because it's looking for "Login" but the log_out page is empty (it's just a codeigniter function which destroys the session and redirects to /)

What is the best way of making webrat realise that it needs to read the page at the end of the redirect?

Zen
  • 7,197
  • 8
  • 35
  • 57

1 Answers1

0

A simple but inefficient way would be to just add a sleep for the approximate time it would take to perform the redirect.

And I click the link Log out
And I wait for 5 seconds
Then I should see the login page

Step definition

When /^I wait for (\d+) seconds$/ do |time|
  sleep time.to_i
end

However this solution is very brittle when it comes to network lag, your wait could either be too long or too short. A better way would be to sleep until the content you're looking for appears.

And I click the link Log out
Then within 30 seconds, I should see the login page

Step definition

Then /^within (\d+) seconds, I should see the login page$/ do |time|
  sleep time.to_i until page.has_text? "Login"
  page.should have_content "Login"
end

If you find yourself using the wait for other steps, the rest of the step after the comma could be generalized.

Francis
  • 119
  • 4