UNPKG

7.49 kBMarkdownView Raw
1Geckodriver [![CI](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/ci.yml/badge.svg)](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/ci.yml) [![Audit](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/audit.yml/badge.svg)](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/audit.yml)
2==========
3
4An NPM wrapper for Mozilla's [Geckodriver](https://github.com/mozilla/geckodriver). It manages to download various (or the latest) Geckodriver versions and provides a programmatic interface to start and stop it within Node.js. __Note:__ this is a wrapper module. If you discover any bugs with Geckodriver, please report them in the [official repository](https://github.com/mozilla/geckodriver).
5
6# Installing
7
8You can install this package via:
9
10```sh
11npm install geckodriver
12```
13
14Or install it globally:
15
16```sh
17npm install -g geckodriver
18```
19
20__Note:__ This installs a `geckodriver` shell script that runs the executable, but on Windows, [`selenium-webdriver`](https://www.npmjs.com/package/selenium-webdriver) looks for `geckodriver.exe`. To use a global installation of this package with [`selenium-webdriver`](https://www.npmjs.com/package/selenium-webdriver) on Windows, copy or link `geckodriver.exe` to a location on your `PATH` (such as the NPM bin directory) after installing this package:
21
22```sh
23mklink %USERPROFILE%\AppData\Roaming\npm\geckodriver.exe %USERPROFILE%\AppData\Roaming\npm\node_modules\geckodriver\geckodriver.exe
24```
25
26Once installed you can start Geckodriver via:
27
28```sh
29npx geckodriver --port=4444
30```
31
32By default, this package downloads Geckodriver when used for the first time through the CLI or the programmatical interface. If you like to download it as part of the NPM install process, set the `GECKODRIVER_AUTO_INSTALL` environment flag, e.g.:
33
34```sh
35GECKODRIVER_AUTO_INSTALL=1 npm i
36```
37
38To get a list of available CLI options run `npx geckodriver --help`. By default this package downloads the latest version of the driver. If you prefer to have it install a custom Geckodriver version you can define the environment variable `GECKODRIVER_VERSION` when running in CLI, e.g.:
39
40```sh
41$ npm i geckodriver
42$ GECKODRIVER_VERSION="0.33.0" npx geckodriver --version
43geckodriver 0.31.0 (b617178ef491 2022-04-06 11:57 +0000)
44
45The source code of this program is available from
46testing/geckodriver in https://hg.mozilla.org/mozilla-central.
47
48This program is subject to the terms of the Mozilla Public License 2.0.
49You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
50```
51
52## Setting a CDN URL for binary download
53
54To set an alternate CDN location for geckodriver binaries, set the `GECKODRIVER_CDNURL` like this:
55
56```sh
57GECKODRIVER_CDNURL=https://INTERNAL_CDN/geckodriver/download
58```
59
60Binaries on your CDN should be located in a subdirectory of the above base URL. For example, `/vxx.xx.xx/*.tar.gz` should be located under `/geckodriver/download` above.
61
62Alternatively, you can add the same property to your .npmrc file.
63
64Default location is set to https://github.com/mozilla/geckodriver/releases/download
65
66## Setting a PROXY URL
67
68Use `HTTPS_PROXY` or `HTTP_PROXY` to set your proxy url.
69
70# Programmatic Interface
71
72You can import this package with Node.js and start the driver as part of your script and use it e.g. with [WebdriverIO](https://webdriver.io).
73
74## Exported Methods
75
76The package exports a `start` and `download` method.
77
78### `start`
79
80Starts an Geckodriver instance and returns a [`ChildProcess`](https://nodejs.org/api/child_process.html#class-childprocess). If Geckodriver is not downloaded it will download it for you.
81
82__Params:__ `GeckodriverParameters` - options to pass into Geckodriver (see below)
83
84__Example:__
85
86```js
87import { start } from 'geckodriver';
88import { remote } from 'webdriverio';
89import waitPort from 'wait-port';
90
91/**
92 * first start Geckodriver
93 */
94const cp = await start({ port: 4444 });
95
96/**
97 * wait for Geckodriver to be up
98 */
99await waitPort({ port: 4444 });
100
101/**
102 * then start WebdriverIO session
103 */
104const browser = await remote({ capabilities: { browserName: 'firefox' } });
105await browser.url('https://webdriver.io');
106console.log(await browser.getTitle()); // prints "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO"
107
108/**
109 * kill Geckodriver process
110 */
111cp.kill();
112```
113
114__Note:__ as you can see in the example above this package does not wait for the driver to be up, you have to manage this yourself through packages like [`wait-on`](https://github.com/jeffbski/wait-on).
115
116### `download`
117
118Method to download an Geckodriver with a particular version. If version parameter is omitted it tries to download the latest available version of the driver.
119
120__Params:__ `string` - version of Geckodriver to download (optional)
121
122## CJS Support
123
124In case your module uses CJS you can use this package as follows:
125
126```js
127const { start } = require('geckodriver')
128// see example above
129```
130
131## Options
132
133The `start` method offers the following options to be passed on to the actual Geckodriver CLI.
134
135### allowHosts
136
137List of hostnames to allow. By default the value of --host is allowed, and in addition if that's a well known local address, other variations on well known local addresses are allowed. If --allow-hosts is provided only exactly those hosts are allowed.
138
139Type: `string[]`<br />
140Default: `[]`
141
142### allowOrigins
143List of request origins to allow. These must be formatted as scheme://host:port. By default any request with an origin header is rejected. If `--allow-origins` is provided then only exactly those origins are allowed.
144
145Type: `string[]`<br />
146Default: `[]`
147
148### binary
149Path to the Firefox binary.
150
151Type: `string`
152
153### connectExisting
154Connect to an existing Firefox instance.
155
156Type: `boolean`<br />
157Default: `false`
158
159### host
160Host IP to use for WebDriver server.
161
162Type: `string`<br />
163Default: `127.0.0.1`
164
165### jsdebugger
166Attach browser toolbox debugger for Firefox.
167
168Type: `boolean`<br />
169Default: `false`
170
171### log
172Set Gecko log level [possible values: `fatal`, `error`, `warn`, `info`, `config`, `debug`, `trace`].
173
174Type: `string`
175
176### logNoTruncated
177Write server log to file instead of stderr, increases log level to `INFO`.
178
179Type: `boolean`
180
181### marionetteHost
182Host to use to connect to Gecko.
183
184Type: `boolean`<br />
185Default: `127.0.0.1`
186
187### marionettePort
188Port to use to connect to Gecko.
189
190Type: `number`<br />
191Default: `0`
192
193### port
194Port to listen on.
195
196Type: `number`
197
198### profileRoot
199Directory in which to create profiles. Defaults to the system temporary directory.
200
201Type: `string`
202
203### geckoDriverVersion
204Version of Geckodriver to start. See https://github.com/mozilla/geckodriver/releases for all available versions, platforms and architecture.
205
206Type: `string`
207
208### customGeckoDriverPath
209Don't download Geckodriver, instead use a custom path to it, e.g. a cached binary.
210
211Type: `string`<br />
212Default: `process.env.GECKODRIVER_FILEPATH`
213
214# Other Browser Driver
215
216If you also look for other browser driver NPM wrapper, you can find them here:
217
218- Chrome: [giggio/node-chromedriver](https://github.com/giggio/node-chromedriver)
219- Microsoft Edge: [webdriverio-community/node-edgedriver](https://github.com/webdriverio-community/node-edgedriver)
220- Safari: [webdriverio-community/node-safaridriver](https://github.com/webdriverio-community/node-safaridriver)
221
222---
223
224For more information on WebdriverIO see the [homepage](https://webdriver.io).