UNPKG

9.28 kBMarkdownView Raw
1# selenium-webdriver
2
3Selenium is a browser automation library. Most often used for testing
4web-applications, Selenium may be used for any task that requires automating
5interaction with the browser.
6
7## Installation
8
9Selenium may be installed via npm with
10
11 npm install selenium-webdriver
12
13You will need to download additional components to work with each of the major
14browsers. The drivers for Chrome, Firefox, and Microsoft's IE and Edge web
15browsers 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
17macOS Sierra. You will need to enable Remote Automation in the Develop menu of
18Safari 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
31The sample below and others are included in the `example` directory. You may
32also find the tests for selenium-webdriver informative.
33
34```javascript
35const {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
51The `Builder` class is your one-stop shop for configuring new WebDriver
52instances. Rather than clutter your code with branches for the various browsers,
53the 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
57const webdriver = require('selenium-webdriver');
58const chrome = require('selenium-webdriver/chrome');
59const firefox = require('selenium-webdriver/firefox');
60
61let driver = new webdriver.Builder()
62 .forBrowser('firefox')
63 .setChromeOptions(/* ... */)
64 .setFirefoxOptions(/* ... */)
65 .build();
66```
67
68Why 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
70browser at runtime through the `SELENIUM_BROWSER` environment variable. For
71example, the `example/google_search.js` script is configured to run against
72Firefox. You can run the example against other browsers just by changing the
73runtime 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
82The standalone Selenium Server acts as a proxy between your script and the
83browser-specific drivers. The server may be used when running locally, but it's
84not recommend as it introduces an extra hop for each request and will slow
85things 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
87connections).
88
89To use the Selenium Server, you will need to install the
90[JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html) and
91download the latest server from [Selenium][release]. Once downloaded, run the
92server with
93
94 java -jar selenium-server-standalone-2.45.0.jar
95
96You may configure your tests to run against a remote server through the Builder
97API:
98
99```javascript
100let driver = new webdriver.Builder()
101 .forBrowser('firefox')
102 .usingServer('http://localhost:4444/wd/hub')
103 .build();
104```
105Or change the Builder's configuration at runtime with the `SELENIUM_REMOTE_URL`
106environment variable:
107
108 SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" node script.js
109
110You can experiment with these options using the `example/google_search.js`
111script provided with `selenium-webdriver`.
112
113## Documentation
114
115API documentation is available online from the [Selenium project][api].
116Additional 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
124Contributions are accepted either through [GitHub][gh] pull requests or patches
125via 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
130Each version of selenium-webdriver will support the latest _semver-minor_
131version of the [LTS] and stable Node releases. All _semver-major_ &
132_semver-minor_ versions between the LTS and stable release will have "best
133effort" support. Following a Selenium release, any _semver-minor_ Node releases
134will also have "best effort" support. Releases older than the latest LTS,
135_semver-major_ releases, and all unstable release branches (e.g. "v.Next")
136are considered strictly unsupported.
137
138For example, suppose the current LTS and stable releases are v6.9.5 and v7.5.0,
139respectively. 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
165If Node releases a new [LTS] each October and a new major version every 6
166months, 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
178Please report any issues using the [Selenium issue tracker][issues]. When using
179the 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
200Licensed to the Software Freedom Conservancy (SFC) under one
201or more contributor license agreements. See the NOTICE file
202distributed with this work for additional information
203regarding copyright ownership. The SFC licenses this file
204to you under the Apache License, Version 2.0 (the
205"License"); you may not use this file except in compliance
206with the License. You may obtain a copy of the License at
207
208http://www.apache.org/licenses/LICENSE-2.0
209
210Unless required by applicable law or agreed to in writing,
211software distributed under the License is distributed on an
212"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
213KIND, either express or implied. See the License for the
214specific language governing permissions and limitations
215under 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