gpt4 book ai didi

linux - 未知错误:在ubuntu上执行Selenium UI测试用例时,DevToolsActivePort文件不存在错误

转载 作者:行者123 更新时间:2023-12-02 19:52:39 24 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 无法启动/产生新的 Web浏览器,即 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-usage
根据 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 David提到:

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.



引用
您可以在以下位置找到一些详细的讨论:
  • org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
  • Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd

  • 奥托罗
    这是 Sandbox故事的链接。

    关于linux - 未知错误:在ubuntu上执行Selenium UI测试用例时,DevToolsActivePort文件不存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59638845/

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