|
1 |
| -## node-geckodriver [](https://github.com/vladikoff/node-geckodriver/actions?workflow=Tests) [](https://www.npmjs.com/package/geckodriver) |
| 1 | +Geckodriver [](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/ci.yml) [](https://github.com/webdriverio-community/node-geckodriver/actions/workflows/audit.yml) |
| 2 | +========== |
2 | 3 |
|
3 |
| -> Downloader for [github.com/mozilla/geckodriver/releases](https://github.com/mozilla/geckodriver/releases) |
| 4 | +An 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). |
4 | 5 |
|
5 |
| -This puts `geckodriver` or `geckodriver.exe` into root of this module. |
| 6 | +# Installing |
6 | 7 |
|
7 |
| -## Install |
| 8 | +You can install this package via: |
8 | 9 |
|
9 |
| -``` |
| 10 | +```sh |
10 | 11 | npm install geckodriver
|
11 | 12 | ```
|
12 | 13 |
|
13 |
| -## Usage |
| 14 | +Or install it globally: |
14 | 15 |
|
15 |
| -There are several ways to use this module: |
| 16 | +```sh |
| 17 | +npm install -g geckodriver |
| 18 | +``` |
16 | 19 |
|
17 |
| -### Use the provided `geckodriver` from `bin` directory. |
| 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: |
18 | 21 |
|
19 |
| -``` |
20 |
| -bin/geckodriver [args] |
| 22 | +```sh |
| 23 | +mklink %USERPROFILE%\AppData\Roaming\npm\geckodriver.exe %USERPROFILE%\AppData\Roaming\npm\node_modules\geckodriver\geckodriver.exe |
21 | 24 | ```
|
22 | 25 |
|
23 |
| -### Use it by requiring: |
| 26 | +Once installed you can start Geckodriver via: |
24 | 27 |
|
25 |
| -``` |
26 |
| -require('geckodriver'); |
| 28 | +```sh |
| 29 | +npx geckodriver --port=4444 |
27 | 30 | ```
|
28 | 31 |
|
29 |
| -### Use it by setting WebDriver capabilities: |
| 32 | +By 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.: |
30 | 33 |
|
31 |
| -``` |
32 |
| -profile.setPreference('marionette', true); |
33 |
| -// Add log level if needed: |
34 |
| -// profile.setPreference('marionette.logging', 'TRACE'); |
| 34 | +```sh |
| 35 | +GECKODRIVER_AUTO_INSTALL=1 npm i |
35 | 36 | ```
|
36 | 37 |
|
37 |
| -### Use it globally: |
| 38 | +To 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.: |
38 | 39 |
|
39 |
| -``` |
40 |
| -npm install -g geckodriver |
41 |
| -geckodriver [args] |
42 |
| -``` |
| 40 | +```sh |
| 41 | +$ npm i geckodriver |
| 42 | +$ GECKODRIVER_VERSION="0.33.0" npx geckodriver --version |
| 43 | +geckodriver 0.31.0 (b617178ef491 2022-04-06 11:57 +0000) |
43 | 44 |
|
44 |
| -Note: This installs a `geckodriver` shell script that runs the executable, but on Windows, selenium-webdriver looks for `geckodriver.exe`. To use a global installation of this package with 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: |
| 45 | +The source code of this program is available from |
| 46 | +testing/geckodriver in https://hg.mozilla.org/mozilla-central. |
45 | 47 |
|
46 |
| -``` |
47 |
| -mklink %USERPROFILE%\AppData\Roaming\npm\geckodriver.exe %USERPROFILE%\AppData\Roaming\npm\node_modules\geckodriver\geckodriver.exe |
| 48 | +This program is subject to the terms of the Mozilla Public License 2.0. |
| 49 | +You can obtain a copy of the license at https://mozilla.org/MPL/2.0/. |
48 | 50 | ```
|
49 | 51 |
|
50 | 52 | ## Setting a CDN URL for binary download
|
51 | 53 |
|
52 | 54 | To set an alternate CDN location for geckodriver binaries, set the `GECKODRIVER_CDNURL` like this:
|
53 | 55 |
|
54 |
| -``` |
| 56 | +```sh |
55 | 57 | GECKODRIVER_CDNURL=https://INTERNAL_CDN/geckodriver/download
|
56 | 58 | ```
|
57 | 59 |
|
58 | 60 | Binaries 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.
|
59 | 61 |
|
60 |
| -Alternatively, you can add the same property to your `.npmrc` file. |
| 62 | +Alternatively, you can add the same property to your .npmrc file. |
61 | 63 |
|
62 | 64 | Default location is set to https://github.com/mozilla/geckodriver/releases/download
|
63 | 65 |
|
64 | 66 | ## Setting a PROXY URL
|
65 | 67 |
|
66 | 68 | Use `HTTPS_PROXY` or `HTTP_PROXY` to set your proxy url.
|
67 | 69 |
|
68 |
| -## Setting a specific version |
69 |
| - |
70 |
| -Use `GECKODRIVER_VERSION` if you require a specific version of gecko driver for your browser version. |
71 |
| - |
72 |
| -## Using a cached download |
73 |
| - |
74 |
| -Use `GECKODRIVER_FILEPATH` to point to a pre-downloaded geckodriver archive that should be extracted during installation. |
75 |
| - |
76 |
| -## Skipping geckodriver download |
77 |
| - |
78 |
| -Use `GECKODRIVER_SKIP_DOWNLOAD` to skip the download of the geckodriver file. |
79 |
| - |
80 |
| - |
81 |
| -## Related Projects |
82 |
| - |
83 |
| -* [node-chromedriver](https://github.com/giggio/node-chromedriver) |
84 |
| - |
85 |
| -## Versions |
86 |
| - |
87 |
| -* [npm module version] - [geckodriver version] |
88 |
| -* 4.0.0 - geckodriver 0.32.0. |
89 |
| -* 3.2.0 - geckodriver 0.32.0, arm64 support. |
90 |
| -* 3.1.0 - geckodriver 0.31.0 |
91 |
| -* 3.0.x - geckodriver 0.30.0, refactored logic, dependency updates. |
92 |
| -* 2.00.x - geckodriver 0.29.1, support changed to node v12+ |
93 |
| -* 1.22.x - geckodriver 0.29.0 |
94 |
| -* 1.21.x - geckodriver 0.28.0 |
95 |
| -* 1.20.x - geckodriver 0.27.0 |
96 |
| -* 1.19.x - geckodriver 0.26.0 |
97 |
| -* 1.18.x - geckodriver 0.26.0 |
98 |
| -* 1.17.x - geckodriver 0.25.0 |
99 |
| -* 1.16.x - geckodriver 0.24.0 and `GECKODRIVER_VERSION` env support |
100 |
| -* 1.15.x - geckodriver 0.24.0 |
101 |
| -* 1.14.x - geckodriver 0.23.0 |
102 |
| -* 1.13.x - geckodriver 0.22.0 |
103 |
| -* 1.12.x - geckodriver 0.21.0 |
104 |
| -* 1.11.x - geckodriver 0.20.0 |
105 |
| -* 1.10.x - geckodriver 0.19.1 |
106 |
| -* 1.9.x - geckodriver 0.19.0 |
107 |
| -* 1.8.x - geckodriver 0.18.0 |
108 |
| -* 1.7.x - geckodriver 0.17.0 |
109 |
| -* 1.6.x - geckodriver 0.16.1 |
110 |
| -* 1.5.x - geckodriver 0.15.0 |
111 |
| -* 1.4.x - geckodriver 0.14.0 |
112 |
| -* 1.3.x - geckodriver 0.13.0 |
113 |
| -* 1.2.x - geckodriver 0.11.1 |
114 |
| -* 1.1.x - geckodriver 0.10 |
115 |
| - |
116 |
| -## Changelog |
117 |
| - |
118 |
| -* 4.0.0 - requires node 14+, drops support for node 12. |
119 |
| -* 3.2.0 - geckodriver 0.32.0, arm64 support for Mac, Linux and Windows, added `GECKODRIVER_ARCH` for custom arch downloads. |
120 |
| -* 3.1.0 - geckodriver 0.31.0 |
121 |
| -* 2.0.1 - fixed proxy download behaviour. |
122 |
| -* 1.20.0 - geckodriver 27. Requires node 8 and higher. Support `HTTPS_PROXY` env and npm_config_geckodriver_version variables. |
123 |
| -* 1.19.0 - geckodriver 26. Dependency updates. |
124 |
| -* 1.18.0 - geckodriver 26. |
125 |
| -* 1.17.0 - geckodriver 25. |
126 |
| -* 1.16.2 - fix issue with 'tar' dependency. |
127 |
| -* 1.16.1 - added support for `GECKODRIVER_FILEPATH` env variable. |
128 |
| -* 1.16.0 - added support for `GECKODRIVER_VERSION` env variable. Set it to `'0.24.0'` to fetch that version. |
129 |
| -* 1.15.1 - fix for the new `.npmignore` pattern matching |
130 |
| -* 1.15.0 - geckodriver 0.24.0 |
131 |
| -* 1.14.0 - geckodriver 0.23.0 |
132 |
| -* 1.13.0 - geckodriver 0.22.0 |
133 |
| -* 1.12.2 - add proxy settings |
134 |
| -* 1.12.1 - adm-zip security fix |
135 |
| -* 1.12.0 - geckodriver 0.21.0 |
136 |
| -* 1.11.0 - geckodriver 0.20.0 |
137 |
| -* 1.10.0 - geckodriver 0.19.1, switch tar package, enable Win32 builds again, process.env.npm_config_geckodriver_cdnurl support |
138 |
| -* 1.9.0 - updated to geckodriver 0.19.0 32-bit windows support removed. |
139 |
| -* 1.8.1 - added geckodriver.exe bin for Windows |
140 |
| -* 1.8.0 - updated to geckodriver 0.18.0 |
141 |
| -* 1.7.1 - 'GECKODRIVER_CDNURL' support added. |
142 |
| -* 1.7.0 - updated to geckodriver 0.17.0 32-bit linux support added. |
143 |
| -* 1.6.1 - updated to geckodriver 0.16.1 |
144 |
| -* 1.6.0 - updated to geckodriver 0.16.0. 32-bit linux support removed. |
145 |
| -* 1.5.0 - updated to geckodriver 0.15.0. |
146 |
| -* 1.4.0 - updated to geckodriver 0.14.0. |
147 |
| -* 1.3.0 - updated to geckodriver 0.13.0. |
148 |
| -* 1.2.1 - added support for Linux 32-bit. |
149 |
| -* 1.2.0 - updated to geckodriver 0.11.1. |
150 |
| -* 1.1.3 - adds Windows support, fixes Windows tests. |
151 |
| -* 1.1.2 - fixed `require` by pointing `package.json main` property to the `lib` file. |
152 |
| -* 1.1.0 - programmatic usage, added `bin` support. |
153 |
| -* 1.0.0 - init release |
| 70 | +# Programmatic Interface |
| 71 | + |
| 72 | +You 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 | + |
| 76 | +The package exports a `start` and `download` method. |
| 77 | + |
| 78 | +### `start` |
| 79 | + |
| 80 | +Starts 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 |
| 87 | +import { start } from 'geckodriver'; |
| 88 | +import { remote } from 'webdriverio'; |
| 89 | +import waitPort from 'wait-port'; |
| 90 | + |
| 91 | +/** |
| 92 | + * first start Geckodriver |
| 93 | + */ |
| 94 | +const cp = await start({ port: 4444 }); |
| 95 | + |
| 96 | +/** |
| 97 | + * wait for Geckodriver to be up |
| 98 | + */ |
| 99 | +await waitPort({ port: 4444 }); |
| 100 | + |
| 101 | +/** |
| 102 | + * then start WebdriverIO session |
| 103 | + */ |
| 104 | +const browser = await remote({ capabilities: { browserName: 'firefox' } }); |
| 105 | +await browser.url('https://webdriver.io'); |
| 106 | +console.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 | + */ |
| 111 | +cp.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 | + |
| 118 | +Method 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 | + |
| 124 | +In case your module uses CJS you can use this package as follows: |
| 125 | + |
| 126 | +```js |
| 127 | +const { start } = require('geckodriver') |
| 128 | +// see example above |
| 129 | +``` |
| 130 | + |
| 131 | +## Options |
| 132 | + |
| 133 | +The `start` method offers the following options to be passed on to the actual Geckodriver CLI. |
| 134 | + |
| 135 | +### allowHosts |
| 136 | + |
| 137 | +List 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 | + |
| 139 | +Type: `string[]`<br /> |
| 140 | +Default: `[]` |
| 141 | + |
| 142 | +### allowOrigins |
| 143 | +List 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 | + |
| 145 | +Type: `string[]`<br /> |
| 146 | +Default: `[]` |
| 147 | + |
| 148 | +### binary |
| 149 | +Path to the Firefox binary. |
| 150 | + |
| 151 | +Type: `string` |
| 152 | + |
| 153 | +### connectExisting |
| 154 | +Connect to an existing Firefox instance. |
| 155 | + |
| 156 | +Type: `boolean`<br /> |
| 157 | +Default: `false` |
| 158 | + |
| 159 | +### host |
| 160 | +Host IP to use for WebDriver server. |
| 161 | + |
| 162 | +Type: `string`<br /> |
| 163 | +Default: `127.0.0.1` |
| 164 | + |
| 165 | +### jsdebugger |
| 166 | +Attach browser toolbox debugger for Firefox. |
| 167 | + |
| 168 | +Type: `boolean`<br /> |
| 169 | +Default: `false` |
| 170 | + |
| 171 | +### log |
| 172 | +Set Gecko log level [possible values: `fatal`, `error`, `warn`, `info`, `config`, `debug`, `trace`]. |
| 173 | + |
| 174 | +Type: `string` |
| 175 | + |
| 176 | +### logNoTruncated |
| 177 | +Write server log to file instead of stderr, increases log level to `INFO`. |
| 178 | + |
| 179 | +Type: `boolean` |
| 180 | + |
| 181 | +### marionetteHost |
| 182 | +Host to use to connect to Gecko. |
| 183 | + |
| 184 | +Type: `boolean`<br /> |
| 185 | +Default: `127.0.0.1` |
| 186 | + |
| 187 | +### marionettePort |
| 188 | +Port to use to connect to Gecko. |
| 189 | + |
| 190 | +Type: `number`<br /> |
| 191 | +Default: `0` |
| 192 | + |
| 193 | +### port |
| 194 | +Port to listen on. |
| 195 | + |
| 196 | +Type: `number` |
| 197 | + |
| 198 | +### profileRoot |
| 199 | +Directory in which to create profiles. Defaults to the system temporary directory. |
| 200 | + |
| 201 | +Type: `string` |
| 202 | + |
| 203 | +### geckoDriverVersion |
| 204 | +Version of Geckodriver to start. See https://github.com/mozilla/geckodriver/releases for all available versions, platforms and architecture. |
| 205 | + |
| 206 | +Type: `string` |
| 207 | + |
| 208 | +### customGeckoDriverPath |
| 209 | +Don't download Geckodriver, instead use a custom path to it, e.g. a cached binary. |
| 210 | + |
| 211 | +Type: `string`<br /> |
| 212 | +Default: `process.env.GECKODRIVER_FILEPATH` |
| 213 | + |
| 214 | +# Other Browser Driver |
| 215 | + |
| 216 | +If 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 | + |
| 224 | +For more information on WebdriverIO see the [homepage](https://webdriver.io). |
0 commit comments