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

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

问题描述

运行代码时,它显示以下错误-电子应用程序

  org.openqa.selenium.WebDriverException:未知错误: DevToolsActivePort文件不存在。 
构建信息:版本:'3.6.0',修订版:'6fbf3ec767',时间:'2017-09-27T15:28:36.4Z'
系统信息:主机:'DESKTOP-GN8LLQU', ip:'192.168.1.20',操作系统名称:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'11 .0.2'
驱动程序信息:驱动程序.version:ChromeDriver

我的代码:

  ChromeOptions opt = new ChromeOptions(); 
//电子申请的路径
opt.setBinary( D:\\FOS\\光纤系统电子electro释放\\角电子0.1.0.exe);
DesiredCapabilities功能=新的DesiredCapabilities();
abilities.setCapability( chromeOptions,opt);
abilities.setBrowserName( chrome);
System.setProperty( webdriver.chrome.driver, E:\\chromedriver_win32(6)\\chromedriver.exe);
WebDriver驱动程序=新的C​​hromeDriver(功能);


解决方案

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


自v2.39以来,Chrome的网络驱动程序(chromedriver.exe)默认情况下会查找名为 DevToolsActivePort 的文件,并在找到文件后读取该文件,以获取当前在chrome中运行的devtools的端口号(在您的情况下,Chrome浏览器中的电子应用 angular-electron 0.1.0.exe正在运行。)


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


您有解决方案有两个选择:


  1. 让电子应用的开发者确保 --remote-debugging-port参数传递到Chrome。

  2. 自动创建自己的解决方案以创建 DevToolsActivePort;文件。

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


我已经开发了一个AutoIT脚本上面的过程是自动完成的,我每次都将其包含在我自己的自动化运行中。


希望这会有所帮助。

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

My Code:

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

解决方案

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.

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).

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. Have the developers of the electron app ensure the "--remote-debugging-port" argument is passed onto Chrome.
  2. Automate your own solution for creating the "DevToolsActivePort" file.

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.

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.

Hope this helps.

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

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