1

I am new to writing tests in Selenium using Javascript and want to ask whether there exists a Driver Manager like WebDriverManager that you can use in JS tests. I've searched quite a lot and couldn't find anything. I think I am just missing something very obvious

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Akzhol
  • 83
  • 1
  • 6

1 Answers1

1

You need to look at webdriver-manager the selenium server and browser driver manager for your end to end tests similar to webdriver-manager from the Protractor repository.

To use as a command line interface:

npm i -g webdriver-manager

webdriver-manager update      // Downloads the latest binaries.
webdriver-manager start       // Starts the selenium server standalone.

To install as a dependency:

npm install -D webdriver-manager

An example running webdriver-manager as a dependency:

import {
  Options,
  setLogLevel,
  shutdown,
  start,
  update,
} from 'webdriver-manager';

const options: Options = {
  browserDrivers: [{
    name: 'chromedriver'     // For browser drivers, we just need to use a valid
                 // browser driver name. Other possible values
                 // include 'geckodriver' and 'iedriver'.
  }],
  server: {
    name: 'selenium',
    runAsNode: true,          // If we want to run as a node. By default
                  // running as detached will set this to true.
    runAsDetach: true         // To run this in detached. This returns the
                  // process back to the parent process.
  }
};
setLogLevel('info');          // Required if we webdriver-manager to log to
                  // console. Not setting this will hide the logs.

describe('some web test', () => {
  beforeAll(async () => {
    await update(options);
    await start(options);
  });

  it('should run some web test', async () => {
    // Your async / await web test with some framework.
  });

  afterAll(async () => {
    await shutdown(options);  // Makes the web request to shutdown the server.
                  // If we do not call shutdown, the java command
                  // will still be running the server on port 4444.
  });
});
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The way I understood it is that I simply need to install webdriver-manager and update it, so once I have it in my dependencies with a specific browser as well (like chromedriver), I can then make use of it through console to update or add different browser, and in actual code simply ```require``` the driver needed. Is that a correct way of thinking about it? – Akzhol Feb 22 '23 at 15:26
  • also, I wanted to ask whether starting selenium server at all is worth when working with multiple browsers or from remote machine is not required. Basically, when to actually start selenium server and when to simply use driver package? – Akzhol Feb 22 '23 at 15:51