gpt4 book ai didi

linux - 未知错误 : DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:04:14 26 4
gpt4 key购买 nike

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

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

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

最佳答案

拇指法则

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.


这个错误信息...

unknown error: DevToolsActivePort file doesn't exist

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

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

但是根据Add --disable-dev-shm-usage to default launch flags似乎添加参数 --disable-dev-shm-usage 将暂时解决问题。

如果您希望启动/跨越新的 Chrome 浏览器 session ,您可以使用以下 Java 解决方案:

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");

禁用-dev-shm-使用

根据 base_switches.cc disable-dev-shm-usage 似乎只在 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

讨论中Add an option to use /tmp instead of /dev/shm大卫提到:

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.


引用

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


结尾

这是 Sandbox 的链接故事。

关于linux - 未知错误 : DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50790733/

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