how to test window.status variable

397 Views Asked by At

I'm using wkhtmlpdf library to convert pdf from the HTML page. this page depends on heavy javascript functions (ajax calls, google maps) so that I had to use --window-status and --javascript-delay options. I'm setting the value window.status="ready_to_print;" when everything is done. It's working properly and pdf are rendering as It should be.

Now I want to create a ruby on rails unit/integration test to check that the HTML page has rendered to the correct state. how can I test this using rpec, capybara or any other way?

2

There are 2 best solutions below

0
Thomas Walpole On BEST ANSWER

With Capybara when you want to get access to the values of JS things you use evaluate_script. In this case that would mean

evaluate_script('window.status')

If you want to wait for that be some value you could wrap it in a loop (possibly with a timeout), or if you just want to verify it is a specific value right now

expect(evaluate_script('window.status')).to eq 'ready_to_print'
0
orde On

I don't know that there's an exposed method in the selenium ruby bindings, but the watir DSL has a Browser::status method, which is implemented as follows and should do the trick:

def status
  execute_script 'return window.status;'
end