gpt4 book ai didi

javascript - 通过 Selenium Webdriver 验证 JavaScript 错误

转载 作者:数据小太阳 更新时间:2023-10-29 08:08:05 24 4
gpt4 key购买 nike

是否有使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com