Selenium Webdriver Turbolinks

I am currently writing selenium webdriver tests for a product that uses turbolinks (in ruby). When I press the button, I have to wait for the turbine to work. When I test jQuery callbacks, I usually expect from my code with:

driver.execute_script 'return jQuery.active == 0'

What can I check with Javascript to check what Turbolinks are? Or is there an element that I can capture to do the same? I see a progress bar at the top, but I cannot find the item anywhere.

EDIT:

I can do something like this:

driver.execute_script "$(document).on('page:load', function () { window.turbolinks = true; });"
driver.execute_script "$(document).on('page:before-change', function () { window.turbolinks = false; });"

when the page loads, and then I can wait for window.turbolinks to be true.

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.execute_script 'return window.turbolinks;' }

Is there a better way to handle this?

+5
source share
2 answers

turbolinks, turbolinks-progress-bar, ?

0

- Selenium . Turbolinks .

, Turbolinks , Turbolinks turbolinks:load ( page:load) - , .

, , -, , :

def wait_for_page_load(driver)
  # listen for Turbolinks to start and stop
  driver.execute_script('document.addEventListener("turbolinks:before-visit", function() { window.turbolinks_is_busy = true; });')
  driver.execute_script('document.addEventListener("turbolinks:load", function() { window.turbolinks_is_busy = false; });')

  # execute the code that causes the page load
  yield

  # optional short sleep, just to be safe
  sleep(1)

  # wait for the various 'page is loading' indicators, including our custom Turbolinks indicator
  wait = Selenium::WebDriver::Wait.new(:timeout => 60)
  wait.until { driver.execute_script("return document.readyState == 'complete' && jQuery.active == 0 && !window.turbolinks_is_busy;") }
end

:

wait_for_page_load(@driver) { @driver.find_element(id: 'a#logout').click }

:

0

All Articles