Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

selenium - Showing Error - unknown error: DevToolsActivePort file doesn't exist - it's electron application (I am using windows OS))

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...