How to refresh Capybara URL in Ruby

Viewed 4522

I've been playing with Capybara and the selenium web-driver to learn about web-automation. I've been trying to refresh a particular page with Capybara. I've seen a few methods but they each have issues that make them not feasible in certain cases.

session.visit link is just doing nothing, as the session is already at that link. I can do session.reset! but then I lose the login.

The few other methods I've seen - don't use Capybara's inbuilt wait functionality. This means if there is heavy server load - or in my tests with a restricted DL/UL rate the 'refresh' happens but then it quickly tries to look for a field in the next page that doesn't exist yet because it hasn't loaded.

So my question is specifically - how do I refresh a page in Capybara without loosing the login session using Capybara's inbuilt wait functionality?

3 Answers

you can do something like:

visit current_path 

or define an RSpec helper:

def reload_page
  visit current_path
end

Capybara now implements a refresh method so you can call it directly in your spec.

Related