System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException error using Azure and Selenium through C#
System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException error using Azure and Selenium through C#
我运行每天计划运行通过 Azure 在远程机器上进行测试。一些测试失败并显示以下错误日志。我该如何解决这个问题?
注意:我没有启动 chrome 驱动程序的方法实现,因为我正在引用其他具有抽象方法的解决方案的 dll。
堆栈:NUnit、C#、Selenium、Visual Studio、Azure、log4Net
OneTimeSetUp:
Automation.Test.Framework.Models.Exceptions.AtGenericException : Error
initializing WebDriver Chrome
----> System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the
'localStorage' property from 'Window': Access is denied for this
document. at :1:1 (Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.36.540470
(e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT
6.3.9600 x86_64)
我猜您应该更改默认 Chrome 功能以允许第三方 cookie:
这个错误信息...
OneTimeSetUp: Automation.Test.Framework.Models.Exceptions.AtGenericException : Error initializing WebDriver Chrome
System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at :1:1 (Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64)
...意味着 ChromeDriver 无法 initiate/spawn 新的 WebBrowser 即 Chrome 浏览器 会话。
您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
- 您正在使用 chromedriver=2.36
- chromedriver=2.36 的发行说明清楚地提到了以下内容:
Supports Chrome v63-65
- 您正在使用 chrome= 77.0
- ChromeDriver v77.0.3865.40 的发行说明清楚地提到了以下内容:
Supports Chrome version 77
因此 Chrome驱动程序 v2.36 和 Chrome 浏览器 v77.0
解决方案
确保:
- Chrome驱动程序 已更新至当前 ChromeDriver v78.0 级别。
- Chrome 已更新为当前 Chrome 版本 78.0 级别。 (根据 ChromeDriver v78.0 release notes)
- 通过 IDE 和 [=32] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- 如果您的基础 Web Client 版本太旧,则卸载它并安装最新的 GA 和发布版本的 Web Client。
- 系统重启。
- 以 非 root 用户身份执行您的
@Test
。
- 始终在
tearDown(){}
方法中调用 driver.quit()
以优雅地关闭和销毁 WebDriver 和 Web Client 实例.
我运行每天计划运行通过 Azure 在远程机器上进行测试。一些测试失败并显示以下错误日志。我该如何解决这个问题?
注意:我没有启动 chrome 驱动程序的方法实现,因为我正在引用其他具有抽象方法的解决方案的 dll。
堆栈:NUnit、C#、Selenium、Visual Studio、Azure、log4Net
OneTimeSetUp: Automation.Test.Framework.Models.Exceptions.AtGenericException : Error initializing WebDriver Chrome ----> System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at :1:1 (Session info: chrome=77.0.3865.90) (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64)
我猜您应该更改默认 Chrome 功能以允许第三方 cookie:
这个错误信息...
OneTimeSetUp: Automation.Test.Framework.Models.Exceptions.AtGenericException : Error initializing WebDriver Chrome
System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at :1:1 (Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64)
...意味着 ChromeDriver 无法 initiate/spawn 新的 WebBrowser 即 Chrome 浏览器 会话。
您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
- 您正在使用 chromedriver=2.36
- chromedriver=2.36 的发行说明清楚地提到了以下内容:
Supports Chrome v63-65
- 您正在使用 chrome= 77.0
- ChromeDriver v77.0.3865.40 的发行说明清楚地提到了以下内容:
Supports Chrome version 77
因此 Chrome驱动程序 v2.36 和 Chrome 浏览器 v77.0
解决方案
确保:
- Chrome驱动程序 已更新至当前 ChromeDriver v78.0 级别。
- Chrome 已更新为当前 Chrome 版本 78.0 级别。 (根据 ChromeDriver v78.0 release notes)
- 通过 IDE 和 [=32] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- 如果您的基础 Web Client 版本太旧,则卸载它并安装最新的 GA 和发布版本的 Web Client。
- 系统重启。
- 以 非 root 用户身份执行您的
@Test
。 - 始终在
tearDown(){}
方法中调用driver.quit()
以优雅地关闭和销毁 WebDriver 和 Web Client 实例.