UNPKG

5.46 kBMarkdownView Raw
1<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
4- [Application Programming Interface (API)](#application-programming-interface-api)
5 - [Sample configuration object](#sample-configuration-object)
6 - [Example](#example)
7 - [selenium.install([opts,] cb)](#seleniuminstallopts-cb)
8 - [selenium.start([opts,] cb)](#seleniumstartopts-cb)
9 - [`Error: Another Selenium process is already running`](#error-another-selenium-process-is-already-running)
10
11<!-- END doctoc generated TOC please keep comment here to allow auto update -->
12
13# Application Programming Interface (API)
14
15## Sample configuration object
16
17Here you can find an up-to-date example of the configuration object:
18[lib/default-config.js](lib/default-config.js)
19
20## Example
21
22```js
23const selenium = require('selenium-standalone');
24
25selenium.install({
26 // check for more recent versions of selenium here:
27 // https://selenium-release.storage.googleapis.com/index.html
28 version: '3.141.59',
29 baseURL: 'https://selenium-release.storage.googleapis.com',
30 drivers: {
31 chrome: {
32 // check for more recent versions of chrome driver here:
33 // https://chromedriver.storage.googleapis.com/index.html
34 version: '87.0.4280.20',
35 arch: process.arch,
36 baseURL: 'https://chromedriver.storage.googleapis.com'
37 },
38 ie: {
39 // check for more recent versions of internet explorer driver here:
40 // https://selenium-release.storage.googleapis.com/index.html
41 version: '3.150.0',
42 arch: process.arch,
43 baseURL: 'https://selenium-release.storage.googleapis.com'
44 }
45 },
46 ignoreExtraDrivers: true,
47 proxy: 'http://localproxy.com', // see https://www.npmjs.com/package/got#proxies
48 requestOpts: { // see https://www.npmjs.com/package/got
49 timeout: 10000
50 },
51 logger: function(message) {
52
53 },
54 progressCb: function(totalLength, progressLength, chunkLength) {
55
56 }
57}, cb);
58```
59
60## selenium.install([opts,] cb)
61
62`opts.version` [selenium version](https://selenium-release.storage.googleapis.com/index.html) to install.
63
64`opts.drivers` map of drivers to download and install along with selenium standalone server.
65
66The current defaults can be found in [lib/default-config.js](lib/default-config.js).
67
68`arch` is either `ia32` or `x64`, it's here because you might want to switch to a particular
69arch [sometimes](https://code.google.com/p/selenium/issues/detail?id=5116#c9).
70
71`baseURL` is used to find the server having the selenium or drivers files.
72
73`opts.ignoreExtraDrivers` only downloads and installs drivers explicity specified.
74
75`opts.basePath` sets the base directory used to store the selenium standalone `.jar` and drivers. Defaults to current working directory + .selenium/
76
77`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.
78
79`opts.logger` will be called if provided with some debugging information about the installation process.
80
81`opts.requestOpts` can be any valid [`got` options object](https://www.npmjs.com/package/got#proxies). You can use this for example to set a timeout.
82
83`cb(err)` called when install finished or errored.
84
85## selenium.start([opts,] cb)
86
87`opts.version` [selenium version](https://selenium-release.storage.googleapis.com/index.html) to install.
88
89`opts.drivers` map of drivers to run along with selenium standalone server, same
90as `selenium.install`.
91
92`opts.ignoreExtraDrivers` only loads and starts drivers explicity specified.
93
94`opts.basePath` sets the base directory used to load the selenium standalone `.jar` and drivers, same as `selenium.install`.
95
96By default all drivers are loaded, you only control and change the versions or archs.
97
98`opts.spawnOptions` [spawn options](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) for the selenium server. Defaults to `undefined`
99
100`opts.javaArgs` array of arguments for the JVM, included between `java` and `-jar` in the command line invocation. Use this option to set properties like `-Xmx=512M` or `-Djava.util.logging.config.file=logging.properties`, for instance. Defaults to `[]`.
101
102`opts.seleniumArgs` array of arguments for the selenium server, passed directly to [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). Defaults to `[]`.
103
104`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.
105
106`opts.javaPath` set the javaPath manually, otherwise we use `[which](https://github.com/isaacs/node-which).sync('java')`.
107
108`opts.requestOpts` can be any valid [`got` options object](https://www.npmjs.com/package/got#proxies). You can use this for example to set a timeout.
109
110`cb(err, child)` called when the server is running and listening, child is the [ChildProcess](https://nodejs.org/api/child_process.html#child_process_class_childprocess) instance created.
111
112So you can `child.kill()` when you are done.
113
114#### `Error: Another Selenium process is already running`
115
116If 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:
117
118```shell
119pkill -f selenium-standalone
120```