是否有使用 Ruby 通过 Selenium WebDriver 验证页面上的 JavaScript 错误的能力?
最佳答案
如果附加到 window.onerror
,您可以记录页面上发生的错误、执行测试并读取任何结果。像这样:
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
这会在您的测试中隔离所有内容,但是您可能会错过在注入(inject)监听器之前发生的错误。您可能需要考虑使用 JavaScript 错误监控服务,例如 TrackJS始终监听错误,然后附加到历史记录以断言您的测试通过。
关于javascript - 通过 Selenium Webdriver 验证 JavaScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31437731/