java - WebDriver 使 Chrome 随机崩溃

标签 java google-chrome selenium

在使用 Selenium ChromeDriver 在 Google Chrome 中运行我的测试套件时,它经常使浏览器崩溃,并显示消息“哇!Chrome 崩溃了。现在重新启动?”。基本上会导致代码中的不确定行为。

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

// Set chromeDriver path
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

ChromeOptions options = new ChromeOptions();

// Force english
options.addArguments("--lang=en");

// Launch chrome
WebDriver driver = new ChromeDriver(options);
... // Click elements, fill text fields, etc.

下面是抛出的异常示例:

[137.372][SEVERE]: Unable to receive message from renderer
org.openqa.selenium.WebDriverException: chrome not reachable
  (Session info: chrome=31.0.1650.63)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.22 seconds
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\PRENAME~1\AppData\Local\Temp\scoped_dir2076_16030}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=31.0.1650.63, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 596eb8b1a989584e999a48b9d94f910d

scoped_dir2076_16030 文件夹中的 chrome_debug.log 文件内容如下:

[9740:9584:0504/013034:ERROR:policy_loader_win.cc(370)] PReg file doesn't exist: C:\Windows\System32\GroupPolicy\Machine\Registry.pol
[7304:8360:0504/013035:ERROR:base_feature_provider.cc(122)] manifestTypes: Allowing web_page contexts requires supplying a value for matches.
[9740:9376:0504/013035:ERROR:policy_loader_win.cc(370)] PReg file doesn't exist: C:\Windows\System32\GroupPolicy\Machine\Registry.pol
[9740:9376:0504/013035:ERROR:policy_loader_win.cc(370)] PReg file doesn't exist: C:\Windows\System32\GroupPolicy\Machine\Registry.pol
[9740:9584:0504/013044:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013045:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013048:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013050:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013052:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013054:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013056:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013101:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013102:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013104:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013105:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013107:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013108:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013111:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013112:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013117:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013119:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013120:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[9740:9584:0504/013132:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[8712:7424:0504/013139:ERROR:ipc_channel_win.cc(404)] pipe error: 232
[9740:9584:0504/013143:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[5276:9684:0504/013152:ERROR:ipc_channel_win.cc(132)] pipe error: 109
[9740:9584:0504/013153:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[8268:10092:0504/013158:ERROR:ipc_channel_win.cc(132)] pipe error: 109
[2528:616:0504/013203:ERROR:ipc_channel_win.cc(132)] pipe error: 109
[9740:9584:0504/013205:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[7112:5484:0504/013215:ERROR:ipc_channel_win.cc(132)] pipe error: 109
[9740:9584:0504/013215:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[5400:8440:0504/013220:ERROR:ipc_channel_win.cc(132)] pipe error: 109
[9740:9584:0504/013227:INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)
[8656:9276:0504/013231:ERROR:ipc_channel_win.cc(132)] pipe error: 109

最佳答案

我发现的一件事是,如果您在关闭 chromeDriver 完成之前停止测试,假设您正在调试器模式下运行并终止运行,则 chromeDriver 进程仍然存在于您的任务管理器中。这可能会累积并耗尽您的所有资源。当我摆脱所有这些仍然存在的进程时,这个问题就不再发生。

关于java - WebDriver 使 Chrome 随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23436655/

相关文章:

java - 使用 java 泛型和接口(interface)扩展可比对象

java - 从使用 Spring 的 DataSourceBuilder 创建的数据源获取到 Postgresql 数据库的连接

selenium - Selenium Webdriver Youtube不计算观看次数

javascript - activeElement 总是返回 document.body

java - 使用 selenium 自动登录 Web 应用程序

java - 我的 selenium 中打开了两个 Firefox 浏览器窗口

java - Spring禁用上下文:component-scan does not detect controllers

java - 带有嵌套事务的 Spring JpaTransactionManager

javascript - 未找到文件 - 文件系统 API、Javascript

javascript - 如何将蓝点放在固定的 Chrome 标签上?