Checking JavaScript error via Selenium Webdriver

Is there such a facility for checking JavaScript errors on a page through Selenium WebDriver using Ruby?

+3


source to share


1 answer


If you attach to window.onerror

, you can record errors that occur on the page, run your test, and read any results. Something like that:

driver.execute_script("window._errors = [];"
driver.execute_script("window.onerror = function(){window._errors.push(arguments);};")
//do your test...
errors = driver.execute_script("return window._errors;")

      



https://code.google.com/p/selenium/wiki/RubyBindings

This test will isolate everything, however you can skip errors that occur before you introduce your listener. You might want to consider using a JavaScript error monitoring service like TrackJS to always listen for errors and then join history to confirm your test passes.

+1


source







All Articles