I'm trying to run some simple tests on a NodeJS app, using Selenium and the Brave browser.
I'm running Big Sur (11.5.2), using Brave version:
Version 1.28.105 Chromium: 92.0.4515.131 (Official Build) (x86_64)
I've downloaded the ChromeDriver, and I've installed in my path:
> which chromedriver
/Users/dd/bin/scripts/chromedriver
> chromedriver --version
ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515@{#1634})
I've created a folder, yarn inited, added the selenium-webdriver
as a dev dependency,
{
"name": "seleniumtest",
"version": "1.0.0",
"description": "seleniumtest",
"main": "index.js",
"license": "MIT",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1"
},
"devDependencies": {
"eslint": "^7.32.0",
"jest": "^27.0.6",
"nodemon": "^2.0.12",
"selenium-webdriver": "^4.0.0-beta.4"
},
"scripts": {
"start": "node ./index.js"
}
}
run up the following Javascript file, index.js
:
const { Builder, By, Key, until } = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('brave').build();
try {
await driver.get('http://www.google.com/');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
await driver.quit();
}
})();
I've fired up the chromedriver:
> chromedriver
Starting ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515@{#1634}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
but when I run yarn start
I get :
UnhandledPromiseRejectionWarning: Error: Do not know how to build driver: browser; did you forget to call usingServer(url)?
If I replace Builder().forBrowser('brave').build();
with Builder().forBrowser('chrome').build();
then Chrome fires up, but the window just sits there trying to load data:,
in the url bar. I tried chromium
- same result as for brave
.
What am I doing wrong?
You can use setChromeBinaryPath function and point the brave binary path to it:
const chrome = require('selenium-webdriver/chrome');
(async function helloSelenium(){
let options = await new chrome.Options();
options.setChromeBinaryPath('/opt/brave.com/brave/brave-browser');
in the forBrowser('brave') replace it with 'chrome', as selenium will do a switch case with that and only the values in Browser enum will be valid (chrome, edge, firefox, internet_explorer, safari, opera);