What is selenium-standalone?
The selenium-standalone npm package is a tool that allows you to easily install and run a standalone Selenium server. This is useful for running automated tests in various browsers without needing to manually set up the Selenium server and browser drivers.
What are selenium-standalone's main functionalities?
Install Selenium Server and Browser Drivers
This feature allows you to install the Selenium server and browser drivers (e.g., ChromeDriver, GeckoDriver) with a single command. The code sample demonstrates how to install the latest versions of the Selenium server and drivers for Chrome and Firefox.
const selenium = require('selenium-standalone');
selenium.install({
version: 'latest',
baseURL: 'https://selenium-release.storage.googleapis.com',
drivers: {
chrome: { version: 'latest' },
firefox: { version: 'latest' }
},
logger: function(message) {
console.log(message);
}
}, function(err) {
if (err) { return console.error(err); }
console.log('Selenium and drivers installed successfully');
});
Start Selenium Server
This feature allows you to start the Selenium server programmatically. The code sample demonstrates how to start the Selenium server and log a message upon successful startup.
const selenium = require('selenium-standalone');
selenium.start(function(err, child) {
if (err) { return console.error(err); }
console.log('Selenium server started successfully');
// child is a ChildProcess instance
});
Stop Selenium Server
This feature allows you to stop the Selenium server programmatically. The code sample demonstrates how to start the Selenium server and then stop it after 10 seconds.
const selenium = require('selenium-standalone');
selenium.start(function(err, child) {
if (err) { return console.error(err); }
console.log('Selenium server started successfully');
// Stop the server after 10 seconds
setTimeout(() => {
child.kill();
console.log('Selenium server stopped');
}, 10000);
});
Other packages similar to selenium-standalone
webdriver-manager
webdriver-manager is a tool for managing WebDriver binaries. It can download, update, and start WebDriver binaries for different browsers. Unlike selenium-standalone, which focuses on running a standalone Selenium server, webdriver-manager is more focused on managing the WebDriver binaries themselves.
selenium-webdriver
selenium-webdriver is the official Selenium package for Node.js. It provides bindings for the WebDriver API and allows you to write automated tests for web applications. While selenium-standalone focuses on setting up and running the Selenium server, selenium-webdriver is used for writing and executing the tests themselves.
nightwatch
Nightwatch is an end-to-end testing framework that uses the WebDriver API. It provides a higher-level API for writing tests and includes built-in support for running tests with Selenium. Nightwatch can manage the Selenium server and browser drivers, similar to selenium-standalone, but it also includes additional features for writing and organizing tests.
⚠️ ATTENTION: we are looking for people taking on maintenance for this package. Read more in webdriverio/selenium-standalone#813
.
Node.js Selenium Standalone
A node based CLI library for launching Selenium with WebDriver support.
Supported Drivers:
Available browsers
By default, Google Chrome, Firefox and Microsoft Edge are available when installed on the host system.
Starting from v6.22
chrome, edgechromium, and geckodriver support latest
as version.
Starting from v9.0.6
supported changes regarding new storage for latest
versions of chromedriver.
Starting from v9.2.0
added new feature 'onlyDriver'
Install & Run
As Global NPM Package
npm install selenium-standalone -g
selenium-standalone install && selenium-standalone start
As a Local NPM Package
npm install selenium-standalone --save-dev
npx selenium-standalone install && npx selenium-standalone start
As a Docker Service
docker run -it -p 4444:4444 webdriverio/selenium-standalone
If you run Chrome or Firefox tests within a Docker container make sure you set capabilities so that the session is headless, e.g.:
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--no-sandbox', '--headless']
}
}
or Firefox:
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['-headless']
}
}
If you are looking for more sophisticated Docker container that allows you to run browser, check out the Docker Selenium project.
Command line interface (CLI)
See CLI docs
Application Programming Interface (API)
See API docs
Tips
Examples of combining with other tools
:woman_technologist: :man_technologist: Contributing
You like this project and want to help making it better? Awesome! Have a look into our Contributor Documentation to get started with setting up the repo.
If you're looking for issues to help out with, check out the issues labelled "good first pick". You can also reach out in our Gitter Channel if you have question on where to start contributing.