显示错误 - 未知错误:DevToolsActivePort 文件不存在 - 它是电子应用程序(我使用的是 Windows 操作系统)) [英] Showing Error - unknown error: DevToolsActivePort file doesn't exist - it's electron application (I am using windows OS))

查看:34
本文介绍了显示错误 - 未知错误:DevToolsActivePort 文件不存在 - 它是电子应用程序(我使用的是 Windows 操作系统))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的代码时,它显示以下错误 - Electron 应用程序

When I run my code it's showing below error - Electron application

org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'DESKTOP-GN8LLQU', ip: '192.168.1.20', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: driver.version: ChromeDriver

我的代码:

ChromeOptions opt = new ChromeOptions();
// path of your Electron Application
opt.setBinary("D:\FOS\fiber-optic-system-electron\release\angular-electron 0.1.0.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", opt);
capabilities.setBrowserName("chrome");
System.setProperty("webdriver.chrome.driver", "E:\chromedriver_win32 (6)\chromedriver.exe");
WebDriver driver = new ChromeDriver(capabilities);

推荐答案

我自己遇到了错误DevToolsActivePort 文件不存在,在我的情况下,错误是正确的,根本原因是电子应用程序本身.

I have been experiencing the error DevToolsActivePort file doesn't exist myself and in my case the error was correct and the root cause was the electron app itself.

从 v2.39 开始,Chrome 的 Web 驱动程序 (chromedriver.exe) 默认会查找名为 DevToolsActivePort 的文件,并在找到时读取它以获取当前在 chrome 中运行的 devtools 的端口号(以及在您的情况下,电子应用程序angular-electron 0.1.0.exe"正在运行的 Chrome 实例).

Since v2.39 Chrome's web driver (chromedriver.exe) by default looks for a file named DevToolsActivePort and when found reads it to obtain the port number of devtools that is currently running in chrome (and in your case the Chrome instance that the electron app "angular-electron 0.1.0.exe" is running).

当您在 Selenium 中创建 ChromeDriver 并包含 --remote-debugging-port=0 参数,或者根本不包含此参数时,chromedriver 将发送 --remote-debugging-port=0 在您的电子应用程序的命令行中(即 angular-electron 0.1.0.exe).如果您的 Electon 应用程序将此参数传递给在其中运行的 Chrome 应用程序,则创建 DevToolsActivePort 文件,chromedriver 可以读取它并获得 devtools 的端口,并且自动化成功.但是,如果您的电子应用程序没有将此参数传递给 Chrome,则永远不会创建 DevToolsActivePort 文件,并且您的 chromedriver 会超时查找它并失败.

When you create a ChromeDriver in Selenium and include the --remote-debugging-port=0 argument, or otherwise do not include this argument at all, then chromedriver will send --remote-debugging-port=0 in the command line to your electron app (ie. angular-electron 0.1.0.exe). If your electon app passes this argument onto the Chrome app running inside it then the DevToolsActivePort file is created, chromedriver can read it and gain the port of devtools, and automation is successful. However if your electron app does not pass this argument to Chrome then the DevToolsActivePort file is never created and your chromedriver times out looking for it and fails.

您有几个解决方案的选择:

You have a couple of options for a solution:

  1. 让电子应用程序的开发人员确保--remote-debugging-port"参数被传递到 Chrome.
  2. 自动化您自己的解决方案,以创建DevToolsActivePort";文件.

在我的情况下,我选择了选项 2.这是手动测试此选项的方法.如果您运行像 SysInternal 的 Tcpview (https://docs.microsoft.com/en-us/sysinternals/downloads/tcpview) 在您的电子应用程序之前,然后 Tcpview 将显示您的电子应用程序正在侦听的端口.这些端口之一将是 Chrome 的 devtools 端口.记下这一点.现在进入 Windows 中的 %temp% 文件夹,因为这是包含 chromedriver 正在寻找的 DevToolsActivePort 文件的临时文件夹的默认位置.在此文件夹中查找以 scoped_dir 为前缀的文件夹.默认情况下,chromedriver 每次运行时都会创建一个.为确保您访问正确的文件夹,最好在运行之前使用 --user-data-dir 参数在 chromedriver 中自行设置此目录名称.进入此文件夹并创建一个名为 DevToolsActivePort 的新文件,并在第一行输入端口号,按 Enter(换行符),然后在第二行输入任意数字.保存文件并关闭.如果您在 60 秒内手动完成整个过程,正在运行的 chromedriver 将读取该文件,获取 Chrome 的 devtools 的端口,连接到它并继续.

In my case I went with option 2. Here's how you can test this option manually. If you run an application like SysInternal's Tcpview (https://docs.microsoft.com/en-us/sysinternals/downloads/tcpview) before your electron app then Tcpview will show you the ports that your electron app is listening on. One of these ports will be the Chrome's devtools port. Note this down. Now go into your %temp% folder in Windows as this is the default location for the temporary folder containing the DevToolsActivePort file that chromedriver is looking for. In this folder look for the folders prefixed with scoped_dir. By default chromedriver will create one these each time you run it. To guarantee you access the correct folder it's best to set this directory name yourself beforehand in chromedriver using the --user-data-dir argument before running it. Go into this folder and create a new file named DevToolsActivePort and enter the port number on the first line, press Enter (newline), and then any number on the second line. Save the file and close. If you complete this entire process manually within 60 seconds the running chromedriver will read that file, get the port of Chrome's devtools, connect to it and continue.

我开发了一个自动执行上述过程的 AutoIT 脚本,我将其包含在我自己的自动化运行中,并且每次都可以正常工作.

I have developed an AutoIT script that does the above process automatically and I include this in my own automation runs and works every time.

希望这会有所帮助.

这篇关于显示错误 - 未知错误:DevToolsActivePort 文件不存在 - 它是电子应用程序(我使用的是 Windows 操作系统))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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