当前位置: 首页 > 知识库问答 >
问题:

测试立即失败,未知错误: DevToolsActivePort文件不存在时运行硒网格通过System d

养慈
2023-03-14

我一直在尝试改变从中的shell脚本启动Selenium网格服务的方式。rclocal系统D服务,但它不工作。脚本如下所示:

#!/bin/bash
java -jar /opt/selenium-server-standalone.jar -role hub -hubConfig hubconfig.json
xvfb-run --server-args="-screen 0 2048x1536x24" java -jar /opt/selenium-server-standalone.jar -role 
node -nodeConfig nodeconfig.json

我创建了两个不同的服务,如下所示:

(Stackoverflow不允许我放置服务的内容,因为它说它的格式不正确)

服务正在正确启动:

selenium hub

● selenium-hub.service - Selenium service
   Loaded: loaded (/etc/systemd/system/selenium-hub.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-10-01 15:53:10 UTC; 2min 41s ago
 Main PID: 23803 (java)
   CGroup: /system.slice/selenium-hub.service
           └─23803 /bin/java -jar /opt/selenium-server-standalone.jar -role hub -hubConfig /home/selenium/hubconfig.json

Oct 01 15:53:12 vm java[23803]: 15:53:12.163 INFO - Selenium build info: version: '3.9.1', revision: '63f7b50'
Oct 01 15:53:12 vm java[23803]: 15:53:12.164 INFO - Launching Selenium Grid hub on port 4444
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.384:INFO::main: Logging initialized @2790ms to org.seleniumhq.jetty9.util.log.StdErrLog
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.492:INFO:osjs.Server:main: jetty-9.4.7.v20170914, build timestamp: 2017-11-21T21:27:37Z, git hash: 82b8fb23f757335bb3329d540ce37a2a2615f0a8
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.524:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.524:INFO:osjs.session:main: No SessionScavenger set, using defaults
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.529:INFO:osjs.session:main: Scavenging every 660000ms
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.538:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@60704c{/,null,AVAILABLE}
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.562:INFO:osjs.AbstractConnector:main: Started ServerConnector@1fe20588{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.562:INFO:osjs.Server:main: Started @2968ms
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Selenium Grid hub is up and running
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Nodes should register to http://1.2.3.4:4444/grid/register/
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Clients should connect to http://1.2.3.4:4444/wd/hub
Oct 01 15:53:14 vm java[23803]: 15:53:14.797 INFO - Registered a node http://1.2.3.4:5555

selenium节点:

● selenium-node.service - Selenium nodes
   Loaded: loaded (/etc/systemd/system/selenium-node.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-10-01 15:53:10 UTC; 6min ago
 Main PID: 23813 (xvfb-run)
   CGroup: /system.slice/selenium-node.service
           ├─23813 /bin/sh /bin/xvfb-run --server-args="-screen 0 2048x1536x24" java -jar /opt/selenium-server-standalone.jar -role node -nodeConfig /home/selenium/nodeconfig.json
           ├─23856 java -jar /opt/selenium-server-standalone.jar -role node -nodeConfig /home/selenium/nodeconfig.json
           ├─24326 /usr/local/bin/chromedriver --port=1713
           ├─24327 /usr/local/bin/chromedriver --port=26741
           ├─24328 /usr/local/bin/chromedriver --port=20065
           ├─24329 /usr/local/bin/chromedriver --port=6459
           ├─24331 /usr/local/bin/chromedriver --port=15872
           ├─24332 /usr/local/bin/chromedriver --port=29475
           ├─24333 /usr/local/bin/chromedriver --port=30216
           ├─24334 /usr/local/bin/chromedriver --port=6955
           ├─24558 /usr/local/bin/chromedriver --port=2425
           ├─24559 /usr/local/bin/chromedriver --port=19304
           ├─24560 /usr/local/bin/chromedriver --port=12150
           ├─24561 /usr/local/bin/chromedriver --port=26147
           ├─24562 /usr/local/bin/chromedriver --port=16545
           ├─24570 /usr/local/bin/chromedriver --port=12780
           ├─24602 /usr/local/bin/chromedriver --port=10959
           ├─24603 /usr/local/bin/chromedriver --port=8970
           ├─24753 /usr/local/bin/chromedriver --port=13438
           ├─24754 /usr/local/bin/chromedriver --port=15725
           └─24772 /usr/local/bin/chromedriver --port=28829

Oct 01 15:55:19 vm xvfb-run[23813]: Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 15725
Oct 01 15:55:19 vm xvfb-run[23813]: Only local connections are allowed.
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.112 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.113 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.114 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.115 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@53702c02
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.115 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@4ae12041
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.116 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.117 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.118 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.118 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.120 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.120 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.121 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.123 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.123 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.124 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.139 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.139 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 26147
Oct 01 15:55:19 vm xvfb-run[23813]: Only local connections are allowed.
Oct 01 15:55:19 vm xvfb-run[23813]: Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

但是,所有测试均失败,并出现相同错误:

OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'

devtoolsativeport的问题源于/dev/shm太小,有时会使浏览器崩溃(https://stackoverflow.com/a/50642913/5364231, https://bugs.chromium.org/p/chromium/issues/detail?id=736452#c64)因此,我已经在功能中添加了——禁用dev shm用法

我认为问题在于服务selenium hub无法与selenium节点通信。非常感谢您的帮助。


共有1个答案

葛泳
2023-03-14

Chrome在启动期间崩溃的一个常见原因是在Linux上以root用户(管理员)身份运行Chrome。虽然可以通过在创建WebDriver会话时传递--no sandbox标志来解决此问题,但这样的配置不受支持,并且非常不推荐。您需要将您的环境配置为以普通用户身份运行Chrome

此错误消息。。。

OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'

...表示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。

您的主要问题是所使用的二进制文件版本之间的不兼容,如下所示:

  • 您正在使用最新的chromedriver=77.0

因此,Selenium客户端v3.9.1、ChromeDriver v77.0和Chrome浏览器v77.0之间存在明显的不匹配

确保:

  • JDK升级到当前级别JDK 8u221
  • Selenium已升级到当前版本3.141。59.
  • ChromeDriver更新为当前ChromeDriver v77。0级
  • Chrome更新到当前的Chrome版本77.0级别。(根据ChromeDriver v77.0发行说明)
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 如果您的基本Web客户端版本太旧,请卸载它并安装最新的GA和Web客户端发布版本
  • 重新启动系统
  • 以非root用户身份执行@Test

您可以在以下内容中找到一些详细的讨论:

  • 组织。openqa。硒。WebDriverException:未知错误:尝试启动Chrome浏览器时DevToolsActivePort文件不存在
  • 未知错误:DevToolsActivePort文件不存在在ubuntu上执行Selenium UI测试用例时出错

下面是沙盒故事的链接。

 类似资料:
  • iam运行一个硒脚本,并继续得到上述错误。这是代码: 所以代码中的注释行对我不起作用。当我添加这一行时,我总是得到这个错误: 并且代码在没有添加上述代码行的情况下也能正常工作。 以下是关于该错误的更多信息: 系统信息: 视窗 7 SP-1 64 位 Chrome信息:版本71.0.3578.98(官方版本)(64位) Java 版本: 10.0.1 请帮我做这件事。

  • 我有一个ubuntu服务器也有UI。U可以通过启动mvn test命令来执行测试用例。但问题是,当我通过另一台机器的终端对机器执行ssh时,我会得到以下错误- 但是,如果我通过remmina远程控制机器,然后执行该机器终端的相同命令,则相同的命令将成功启动chrome。

  • 使用Selenium的Python脚本无法创建Chrome的实例,尽管版本是正确的并且安装了UI。 我已经在这里看了类似的线程,似乎没有一个解决了这个问题。代码在Windows上工作 - 一旦我尝试在Linux上执行它,它就不再有效。我的预期目标是让它在视觉上打开Chrome,因此我不是在寻找涉及虚拟显示器的解决方案。 我有谷歌浏览器75.0.3770.100安装我也有ChromeDriver 7

  • 问题内容: 我正在尝试使用URL启动chrome,浏览器启动,此后它什么也不做。 1分钟后,我看到以下错误: 我的配置: Chrome:66 Chrome浏览器:2.39.56 PS 在Firefox中一切正常 问题答案: 更新: 我可以解决问题,现在可以使用所需的网址访问Chrome。 尝试提供的解决方案的结果: 我尝试了上面提供的所有设置,但无法解决问题 有关问题的说明: 根据我的观察,当ch

  • 注: 在testng xml中,如果我将parallel=更改为类或方法,那么它可以很好地运行测试,但它不是并行地一个接一个地运行测试。 如果我保持parallel=“tests”,那么它会并行运行,但它会在同一个VM中打开同一个浏览器三次,这是不正确的。 我的设置: 我设置了11个虚拟机,每个盒子上的每个浏览器都初始化了Selenium网格节点。我已经创建了testng xml,以便在每个框上运