未知错误:在 ubuntu 上执行 Selenium UI 测试用例时,DevToolsActivePort 文件不存在错误 [英] unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu

查看:48
本文介绍了未知错误:在 ubuntu 上执行 Selenium UI 测试用例时,DevToolsActivePort 文件不存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也有一个带有 UI 的 ubuntu 服务器.你可以通过触发 mvn test 命令来执行测试用例.但问题是当我从另一台机器通过终端对机器执行 ssh 时,我收到以下错误-

 未知错误:DevToolsActivePort 文件不存在(驱动程序信息:chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-121-generic x86_64)(警告:服务器没有提供任何堆栈跟踪信息)命令持续时间或超时:60.04 秒构建信息:版本:'3.8.1',修订版:'6e95a6684b',时间:'2017-12-01T18:33:54.468Z'系统信息:主机:'ubuntu-test',ip:'XXXX',os.name:'Linux',os.arch:'amd64',os.version:'4.4.0-121-generic',java.版本:'1.8.0_171'驱动程序信息:driver.version:ChromeDriver

但是,如果我通过 remmina 远程控制机器,然后执行该机器终端的相同命令,则相同的命令会成功启动 chrome.

解决方案

Thumb rule

<块引用>

Chrome 在启动过程中崩溃的一个常见原因是以 root 用户(administrator>) 在 Linux 上.虽然可以通过在创建 WebDriver 会话时传递 --no-sandbox 标志来解决此问题,但这种配置不受支持且非常不鼓励.您需要将环境配置为以普通用户身份运行 Chrome.


这个错误信息...

 未知错误:DevToolsActivePort 文件不存在

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

您的代码试验和所有二进制文件的版本信息会给我们一些关于问题所在的提示.

但是根据 将 --disable-dev-shm-usage 添加到默认启动标志 似乎添加参数 --disable-dev-shm-usage 将暂时解决问题.

如果您希望发起/跨新的 Chrome 浏览器会话,您可以使用以下 Java 解决方案:

System.setProperty(webdriver.chrome.driver", C:\path\to\chromedriver.exe");ChromeOptions options = new ChromeOptions();options.addArguments("--disable-dev-shm-usage");//克服资源有限的问题options.addArguments(开始最大化");//以最大化模式打开浏览器options.addArguments("disable-infobars");//禁用信息栏options.addArguments("--disable-extensions");//禁用扩展options.addArguments("--disable-gpu");//仅适用于 windows 操作系统options.addArguments("--no-sandbox");//绕过操作系统安全模型WebDriver driver = new ChromeDriver(options);driver.get(https://google.com");


禁用-dev-shm-usage

根据 base_switches.ccdisable-dev-shm-usage 似乎只在 Linix OS 上有效:

#if 已定义(OS_LINUX) &&!defined(OS_CHROMEOS)///dev/shm 分区在某些 VM 环境中太小,导致//Chrome 失败或崩溃(参见 http://crbug.com/715363).使用这个标志来//解决此问题(将始终使用临时目录来创建//匿名共享内存文件).const char kDisableDevShmUsage[] = "disable-dev-shm-usage";#万一

在讨论中 添加一个使用/tmp 的选项/dev/shm 大卫提到:

<块引用>

我认为这取决于/dev/shm 和/tmp 的安装方式.如果它们都安装为 tmpfs,我假设不会有任何区别.如果由于某种原因/tmp 没有映射为 tmpfs(我认为 systemd 默认映射为 tmpfs),chrome 共享内存管理在创建匿名共享文件时总是将文件映射到内存中,所以即使在这种情况下也不应该差别很大.我想你可以在启用标志的情况下强制进行遥测测试,看看它是如何进行的.

<块引用>

至于为什么不默认使用,这是共享内存团队的推论,我想应该默认使用/dev/shm作为共享内存是有道理的.

<块引用>

最终所有这些都应该转向使用 memfd_create,但我认为这不会很快发生,因为它需要显着重构 Chrome 内存管理.


参考

您可以在以下位置找到一些详细的讨论:


尾声

这是的链接沙盒故事.

I have an ubuntu server having the UI as well. U can execute the test cases by firing mvn test command. But the problem is when I do ssh of the machine through the terminal from another machine I get the following error-

unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-121-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.04 seconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ubuntu-test', ip: 'X.X.X.X', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-121-generic', java.version: '1.8.0_171'
Driver info: driver.version: ChromeDriver

but the same command starts chrome successfully if I take remote of the machine through remmina and then execute the same command of this machines terminal.

解决方案

Thumb rule

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


This error message...

unknown error: DevToolsActivePort file doesn't exist

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

Your code trials and the versioning information of all the binaries would have given us some hint about what's going wrong.

However as per Add --disable-dev-shm-usage to default launch flags seems adding the argument --disable-dev-shm-usage will temporary solve the issue.

If you desire to initiate/span a new Chrome Browser session you can use the following Java solution:

System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");


disable-dev-shm-usage

As per base_switches.cc disable-dev-shm-usage seems to be valid only on Linix OS:

#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif

In the discussion Add an option to use /tmp instead of /dev/shm David mentions:

I think it would depend on how are /dev/shm and /tmp mounted. If they are both mounted as tmpfs I'm assuming there won't be any difference. if for some reason /tmp is not mapped as tmpfs (and I think is mapped as tmpfs by default by systemd), chrome shared memory management always maps files into memory when creating an anonymous shared files, so even in that case shouldn't be much difference. I guess you could force telemetry tests with the flag enabled and see how it goes.

As for why not use by default, it was a pushed back by the shared memory team, I guess it makes sense it should be useing /dev/shm for shared memory by default.

Ultimately all this should be moving to use memfd_create, but I don't think that's going to happen any time soon, since it will require refactoring Chrome memory management significantly.


Reference

You can find a couple of detailed discussions in:


Outro

Here is the link to the Sandbox story.

这篇关于未知错误:在 ubuntu 上执行 Selenium UI 测试用例时,DevToolsActivePort 文件不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆