1 | # selenium-webdriver
|
2 |
|
3 | Selenium is a browser automation library. Most often used for testing
|
4 | web-applications, Selenium may be used for any task that requires automating
|
5 | interaction with the browser.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | Selenium may be installed via npm with
|
10 |
|
11 | npm install selenium-webdriver
|
12 |
|
13 | You will need to download additional components to work with each of the major
|
14 | browsers. The drivers for Chrome, Firefox, and Microsoft's IE and Edge web
|
15 | browsers are all standalone executables that should be placed on your system
|
16 | [PATH]. Apple's safaridriver is shipped with Safari 10 for OS X El Capitan and
|
17 | macOS Sierra. You will need to enable Remote Automation in the Develop menu of
|
18 | Safari 10 before testing.
|
19 |
|
20 |
|
21 | | Browser | Component |
|
22 | | ----------------- | ---------------------------------- |
|
23 | | Chrome | [chromedriver(.exe)][chrome] |
|
24 | | Internet Explorer | [IEDriverServer.exe][release] |
|
25 | | Edge | [MicrosoftWebDriver.msi][edge] |
|
26 | | Firefox | [geckodriver(.exe)][geckodriver] |
|
27 | | Safari | [safaridriver] |
|
28 |
|
29 | ## Usage
|
30 |
|
31 | The sample below and others are included in the `example` directory. You may
|
32 | also find the tests for selenium-webdriver informative.
|
33 |
|
34 | ```javascript
|
35 | const {Builder, By, Key, until} = require('selenium-webdriver');
|
36 |
|
37 | (async function example() {
|
38 | let driver = await new Builder().forBrowser('firefox').build();
|
39 | try {
|
40 | await driver.get('http://www.google.com/ncr');
|
41 | await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
|
42 | await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
|
43 | } finally {
|
44 | await driver.quit();
|
45 | }
|
46 | })();
|
47 | ```
|
48 |
|
49 | ### Using the Builder API
|
50 |
|
51 | The `Builder` class is your one-stop shop for configuring new WebDriver
|
52 | instances. Rather than clutter your code with branches for the various browsers,
|
53 | the builder lets you set all options in one flow. When you call
|
54 | `Builder#build()`, all options irrelevant to the selected browser are dropped:
|
55 |
|
56 | ```javascript
|
57 | const webdriver = require('selenium-webdriver');
|
58 | const chrome = require('selenium-webdriver/chrome');
|
59 | const firefox = require('selenium-webdriver/firefox');
|
60 |
|
61 | let driver = new webdriver.Builder()
|
62 | .forBrowser('firefox')
|
63 | .setChromeOptions(/* ... */)
|
64 | .setFirefoxOptions(/* ... */)
|
65 | .build();
|
66 | ```
|
67 |
|
68 | Why would you want to configure options irrelevant to the target browser? The
|
69 | `Builder`'s API defines your _default_ configuration. You can change the target
|
70 | browser at runtime through the `SELENIUM_BROWSER` environment variable. For
|
71 | example, the `example/google_search.js` script is configured to run against
|
72 | Firefox. You can run the example against other browsers just by changing the
|
73 | runtime environment
|
74 |
|
75 | # cd node_modules/selenium-webdriver
|
76 | node example/google_search
|
77 | SELENIUM_BROWSER=chrome node example/google_search
|
78 | SELENIUM_BROWSER=safari node example/google_search
|
79 |
|
80 | ### The Standalone Selenium Server
|
81 |
|
82 | The standalone Selenium Server acts as a proxy between your script and the
|
83 | browser-specific drivers. The server may be used when running locally, but it's
|
84 | not recommend as it introduces an extra hop for each request and will slow
|
85 | things down. The server is required, however, to use a browser on a remote host
|
86 | (most browser drivers, like the IEDriverServer, do not accept remote
|
87 | connections).
|
88 |
|
89 | To use the Selenium Server, you will need to install the
|
90 | [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html) and
|
91 | download the latest server from [Selenium][release]. Once downloaded, run the
|
92 | server with
|
93 |
|
94 | java -jar selenium-server-standalone-2.45.0.jar
|
95 |
|
96 | You may configure your tests to run against a remote server through the Builder
|
97 | API:
|
98 |
|
99 | ```javascript
|
100 | let driver = new webdriver.Builder()
|
101 | .forBrowser('firefox')
|
102 | .usingServer('http://localhost:4444/wd/hub')
|
103 | .build();
|
104 | ```
|
105 | Or change the Builder's configuration at runtime with the `SELENIUM_REMOTE_URL`
|
106 | environment variable:
|
107 |
|
108 | SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" node script.js
|
109 |
|
110 | You can experiment with these options using the `example/google_search.js`
|
111 | script provided with `selenium-webdriver`.
|
112 |
|
113 | ## Documentation
|
114 |
|
115 | API documentation is available online from the [Selenium project][api].
|
116 | Additional resources include
|
117 |
|
118 | - the #selenium channel on freenode IRC
|
119 | - the [selenium-users@googlegroups.com][users] list
|
120 | - [SeleniumHQ](http://www.seleniumhq.org/docs/) documentation
|
121 |
|
122 | ## Contributing
|
123 |
|
124 | Contributions are accepted either through [GitHub][gh] pull requests or patches
|
125 | via the [Selenium issue tracker][issues]. You must sign our
|
126 | [Contributor License Agreement][cla] before your changes will be accepted.
|
127 |
|
128 | ## Node Support Policy
|
129 |
|
130 | Each version of selenium-webdriver will support the latest _semver-minor_
|
131 | version of the [LTS] and stable Node releases. All _semver-major_ &
|
132 | _semver-minor_ versions between the LTS and stable release will have "best
|
133 | effort" support. Following a Selenium release, any _semver-minor_ Node releases
|
134 | will also have "best effort" support. Releases older than the latest LTS,
|
135 | _semver-major_ releases, and all unstable release branches (e.g. "v.Next")
|
136 | are considered strictly unsupported.
|
137 |
|
138 | For example, suppose the current LTS and stable releases are v6.9.5 and v7.5.0,
|
139 | respectively. Then a Selenium release would have the following support levels:
|
140 |
|
141 | | Version | Support |
|
142 | | ------- | ------------- |
|
143 | | <= 6.8 | _unsupported_ |
|
144 | | 6.9 | supported |
|
145 | | 7.0-4 | best effort |
|
146 | | 7.5 | supported |
|
147 | | >= 7.5 | best effort |
|
148 | | v.Next | _unsupported_ |
|
149 |
|
150 | ### Support Level Definitions
|
151 |
|
152 | - _supported:_ A selenium-webdriver release will be API compatible with the
|
153 | platform API, without the use of runtime flags.
|
154 |
|
155 | - _best effort:_ Bugs will be investigated as time permits. API compatibility is
|
156 | only guaranteed where required by a _supported_ release. This effectively
|
157 | means the adoption of new JS features, such as ES2015 modules, will depend
|
158 | on what is supported in Node's LTS.
|
159 |
|
160 | - _unsupported:_ Bug submissions will be closed as will-not-fix and API
|
161 | compatibility is not guaranteed.
|
162 |
|
163 | ### Projected Support Schedule
|
164 |
|
165 | If Node releases a new [LTS] each October and a new major version every 6
|
166 | months, the support window for selenium-webdriver will be roughly:
|
167 |
|
168 | | Date | LTS | Stable |
|
169 | | --------- | ---: | -----: |
|
170 | | (current) | 8.9 | 9.0 |
|
171 | | 2018-04 | 8.x | 10.0 |
|
172 | | 2018-10 | 10.x | 11.0 |
|
173 | | 2019-04 | 10.x | 12.0 |
|
174 | | 2019-10 | 12.x | 13.0 |
|
175 |
|
176 | ## Issues
|
177 |
|
178 | Please report any issues using the [Selenium issue tracker][issues]. When using
|
179 | the issue tracker
|
180 |
|
181 | - __Do__ include a detailed description of the problem.
|
182 | - __Do__ include a link to a [gist](http://gist.github.com/) with any
|
183 | interesting stack traces/logs (you may also attach these directly to the bug
|
184 | report).
|
185 | - __Do__ include a [reduced test case][reduction]. Reporting "unable to find
|
186 | element on the page" is _not_ a valid report - there's nothing for us to
|
187 | look into. Expect your bug report to be closed if you do not provide enough
|
188 | information for us to investigate.
|
189 | - __Do not__ use the issue tracker to submit basic help requests. All help
|
190 | inquiries should be directed to the [user forum][users] or #selenium IRC
|
191 | channel.
|
192 | - __Do not__ post empty "I see this too" or "Any updates?" comments. These
|
193 | provide no additional information and clutter the log.
|
194 | - __Do not__ report regressions on closed bugs as they are not actively
|
195 | monitored for updates (especially bugs that are >6 months old). Please open a
|
196 | new issue and reference the original bug in your report.
|
197 |
|
198 | ## License
|
199 |
|
200 | Licensed to the Software Freedom Conservancy (SFC) under one
|
201 | or more contributor license agreements. See the NOTICE file
|
202 | distributed with this work for additional information
|
203 | regarding copyright ownership. The SFC licenses this file
|
204 | to you under the Apache License, Version 2.0 (the
|
205 | "License"); you may not use this file except in compliance
|
206 | with the License. You may obtain a copy of the License at
|
207 |
|
208 | http://www.apache.org/licenses/LICENSE-2.0
|
209 |
|
210 | Unless required by applicable law or agreed to in writing,
|
211 | software distributed under the License is distributed on an
|
212 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
213 | KIND, either express or implied. See the License for the
|
214 | specific language governing permissions and limitations
|
215 | under the License.
|
216 |
|
217 | [LTS]: https://github.com/nodejs/LTS
|
218 | [PATH]: http://en.wikipedia.org/wiki/PATH_%28variable%29
|
219 | [api]: http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/
|
220 | [cla]: http://goo.gl/qC50R
|
221 | [chrome]: http://chromedriver.storage.googleapis.com/index.html
|
222 | [gh]: https://github.com/SeleniumHQ/selenium/
|
223 | [issues]: https://github.com/SeleniumHQ/selenium/issues
|
224 | [edge]: http://go.microsoft.com/fwlink/?LinkId=619687
|
225 | [geckodriver]: https://github.com/mozilla/geckodriver/releases/
|
226 | [reduction]: http://www.webkit.org/quality/reduction.html
|
227 | [release]: http://selenium-release.storage.googleapis.com/index.html
|
228 | [users]: https://groups.google.com/forum/#!forum/selenium-users
|
229 | [safaridriver]: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html#//apple_ref/doc/uid/TP40014305-CH11-DontLinkElementID_28
|