selenium-webdriverrspeccapybaraminitestcapybara-webkit

how to test window.status variable


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?


Solution

  • 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'