Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh Capybara URL in Ruby

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?

like image 773
Leon92 Avatar asked Jul 17 '17 00:07

Leon92


2 Answers

you can do something like:

visit current_path 

or define an RSpec helper:

def reload_page
  visit current_path
end
like image 141
Andres Leon Avatar answered Sep 29 '22 16:09

Andres Leon


Since you're using selenium, you can either use the master branch of Capybara and call

session.refresh

or you can stick with the current release version and call

session.driver.browser.navigate.refresh

If the page you're trying to refresh was a POST it may pop up an "are you sure you want to resbumit" modal, in which case you'd need something like

session.accept_confirm do
  session.driver.browser.navigate.refresh
end
like image 39
Thomas Walpole Avatar answered Sep 29 '22 16:09

Thomas Walpole