'How do I get selenium to open my electron app?
I'm attempting to setup Selenium to test my electron app. So far I have the code from the Electron documentation, however, this only opens the HTML file, not my actual app. Here is my code:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'chromeOptions': {
// Here is the path to your Electron binary.
binary: '../../node_modules/electron/dist/electron.exe'
}
})
.forBrowser('chrome')
.build();
const current_path = path.join(__dirname, "../../dist/public/index.html");
driver.get('file://' + current_path);
How can I get it to open my app?
I've been trying to figure this out for several days, and all the other articles and stackoverflow posts either point to Spectron (which is now deprecated) or don't explain how to open my own app and not a different website.
EDIT: I figured out that adding "args": ['--app=PATH_TO_PROJECT_DIR')]
in the chromeOptions object , and changing the name to "goog:chromeOptions"
, makes it open to the correct file path, however, now I get the following error:
WebDriverError: unknown error: no chrome binary at ../../node_modules/electron/dist/electron.exe
Changing back to "chromeOptions" stops it from opening the app directory, but does open a blank chrome window.
Solution 1:[1]
The solution was to:
- Replace
'../../node_modules/electron/dist/electron.exe'
withpath.join(__dirname, '../../node_modules/electron/dist/electron.exe')
- To change
chromeOptions
togoog:chromeOptions
- To add
"args": [path.join(__dirname, '../../')]
to the goog:chromeOptions object.
Working Code:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'goog:chromeOptions': {
// Here is the path to your Electron binary.
"binary": path.join(__dirname, '../../node_modules/electron/dist/electron.exe'),
"args": ['--app=' + path.join(__dirname, "../../")]
}
})
.forBrowser('chrome')
.build();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | S.B |