3

I want to have the latest browser engines without manually downloading them, thus I found webdriver manager. Though selenium documentation refers, regarding webdriver manager, that

// There is not a recommended driver manager for JavaScript at this time

I found though an NPM package named webdriver-manager but they don't mention how to integrate it with nodeJs.

Right now, I am just running webdriver-manager update --out_dir ~/.local/bin/ to download the files into a directory included in PATH, but I still have to rename the executable, because selenium-webdriver does not detect them automatically.

I'm using the traditional code for headless browsers

const { Builder, By, until } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const firefox = require('selenium-webdriver/firefox')

//...

let driver
switch (browserForTest) { // browserForTest is fetched from argv
  case 'firefox':
    driver = await new Builder()
      .forBrowser('firefox')
      .setFirefoxOptions(new firefox.Options().headless().windowSize(screen))
      .build()
    break
  case 'chrome':
    driver = await new Builder()
      .forBrowser('chrome')
      .setChromeOptions(new chrome.Options().headless().windowSize(screen))
      .build()
    break
  default:
    throw Error('Wrong browser: ' + browserForTest)
}

Anyone has used webdriver-manager with nodeJS? How do you integrate it? How do you use selenium webdriver manager with node/javascript?

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
  • have you found an answer yet? – Fath Feb 05 '22 at 06:50
  • 2
    @Fath check it https://github.com/jfoclpf/autocosts/blob/master/.github/workflows/firefox.yml – João Pimentel Ferreira Feb 06 '22 at 14:21
  • 1
    A starting point for finding your answer would be to look at [how the bin-script works](https://github.com/angular/webdriver-manager/blob/legacy/bin/webdriver-manager). From [this particular commit](https://github.com/angular/webdriver-manager/blob/00740238dc31b71d5dfd0db6c929b47b43c7b0d8/bin/webdriver-manager), the lines you want to focus on are 41,48,and 55 which show you how the "main" script is included into the bin script. The missing "built" directory is made by the gulpfile in the git repo's root. It just simply copies the lib folder into the built folder. – DaMaxContent Feb 15 '23 at 20:54

1 Answers1

1

webdriver-manager(master): README.md:

see webdriver-manager's master branch (this isn't their main branch, the legacy branch is)

Use as a dependency

To install this as a dependency: npm install -D webdriver-manager. The following is an example running webdriver-manager as a dependency. The test downloads the providers and starts the selenium server standalone as detached. After the test, it will shutdown the selenium server standalone.

import {
  Options,
  setLogLevel,
  shutdown,
  start,
  update,
} from 'webdriver-manager';
DaMaxContent
  • 150
  • 1
  • 13