Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
selenium-standalone
Advanced tools
installs a `selenium-standalone` command line to install and start a standalone selenium server
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.
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);
});
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 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 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.
Command line or programmatic install and launch of selenium standalone server, chrome driver, internet explorer driver, firefox driver and phantomjs
It will install a selenium-standalone
command line that will be able to install
selenium server and start
firefox, chrome, internet explorer or phantomjs for your tests.
npm install selenium-standalone@latest -g
selenium-standalone install
selenium-standalone start
# simple, use defaults and latest selenium
selenium-standalone install
selenium-standalone start
# install defaults, but silently
selenium-standalone install --silent
# specify selenium args, everything after -- is for selenium
selenium-standalone start -- -debug
# choose selenium version
selenium-standalone install --version=2.45.0 --baseURL=https://selenium-release.storage.googleapis.com
# choose chrome driver version
selenium-standalone install --drivers.chrome.version=2.15 --drivers.chrome.baseURL=https://chromedriver.storage.googleapis.com
# choose ie driver architecture
selenium-standalone start --drivers.ie.arch=ia32 --drivers.ie.baseURL=https://selenium-release.storage.googleapis.com
# specify hub and nodes to setup your own selenium grid
selenium-standalone start -- -role hub
selenium-standalone start -- -role node -hub http://localhost:4444/grid/register
selenium-standalone start -- -role node -hub http://localhost:4444/grid/register -port 5556
var selenium = require('selenium-standalone');
selenium.install({
// check for more recent versions of selenium here:
// https://selenium-release.storage.googleapis.com/index.html
version: '2.45.0',
baseURL: 'https://selenium-release.storage.googleapis.com',
drivers: {
chrome: {
// check for more recent versions of chrome driver here:
// https://chromedriver.storage.googleapis.com/index.html
version: '2.15',
arch: process.arch,
baseURL: 'https://chromedriver.storage.googleapis.com'
},
ie: {
// check for more recent versions of internet explorer driver here:
// https://selenium-release.storage.googleapis.com/index.html
version: '2.45.0',
arch: process.arch,
baseURL: 'https://selenium-release.storage.googleapis.com'
}
},
logger: function(message) {
},
progressCb: function(totalLength, progressLength, chunkLength) {
}
}, cb);
opts.version
selenium version to install.
opts.drivers
map of drivers to download and install along with selenium standalone server.
Here are the current defaults:
{
chrome: {
version: '2.15',
arch: process.arch,
baseURL: 'https://chromedriver.storage.googleapis.com'
},
ie: {
version: '2.45.0',
arch: process.arch,
baseURL: 'https://selenium-release.storage.googleapis.com'
}
}
arch
is either ia32
or x64
, it's here because you might want to switch to a particular
arch sometimes.
baseURL
is used to find the server having the selenium or drivers files.
opts.basePath
sets the base directory used to store the selenium standalone .jar
and drivers. Defaults to current working directory + .selenium/
opts.progressCb(totalLength, progressLength, chunkLength)
will be called if provided with raw bytes length numbers about the current download process. It is used by the command line to show a progress bar.
opts.logger
will be called if provided with some debugging information about the installation process.
cb(err)
called when install finished or errored.
opts.drivers
map of drivers to run along with selenium standalone server, same
as selenium.install
.
opts.basePath
sets the base directory used to load the selenium standalone .jar
and drivers, same as selenium.install
.
By default all drivers are loaded, you only control and change the versions or archs.
opts.spawnOptions
spawn options for the selenium server. Defaults to undefined
opts.seleniumArgs
array of arguments for the selenium server, passed directly to child_process.spawn. Defaults to []
.
opts.spawnCb
will be called if provided as soon as the selenium child process was spawned. It may be interesting if you want to do some more debug.
opts.javaPath
set the javaPath manually, otherwise we use [which](https://github.com/isaacs/node-which).sync('java')
cb(err, child)
called when the server is running and listening, child is the ChildProcess instance created.
So you can child.kill()
when you are done.
Error: Another Selenium process is already running
If you're getting this error, it means that you didn't shut down the server successfully the last time you started it, so it's still running in the background. You can kill it by running:
pkill -f selenium-standalone
By default, google chrome, firefox and phantomjs are available when installed on the host system.
After installing selenium-standalone globally, execute the following commands to run selenium-standalone when your machine starts!
ln -s /usr/local/bin/selenium-standalone /etc/init.d/
update-rc.d selenium-standalone defaults
For more information: https://stackoverflow.com/questions/3666794/selenium-server-on-startup/30392437#30392437
On linux,
To run headlessly, you can use xvfb:
xvfb-run --server-args="-screen 0, 1366x768x24" selenium-standalone start
By default, Selenium sends logging messages to stderr.
The selenium-standalone cli tool (selenium-standalone start
) will output the logging messages to your process.stderr
. So you do see them in the console.
If you are using the programmatic API, you can retrieve the stderr
messages by doing this:
var selenium = require('selenium-standalone');
selenium.start(function(err, child) {
child.stderr.on('data', function(data){
console.log(data.toString());
});
});
You can also forward the stderr
to your process.stderr
like the cli does:
var selenium = require('selenium-standalone');
selenium.start({
spawnOptions: {
stdio: 'inherit'
}
}, function(err, child) {
// child.stderr now sent to your `process.stderr`
});
FAQs
installs a `selenium-standalone` command line to install and start a standalone selenium server
We found that selenium-standalone demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.