File tree 3 files changed +45
-5
lines changed
javascript/node/selenium-webdriver
3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 8
8
9
9
### API Changes
10
10
11
- * Added ` selenium-webdriver/firefox.Options#addArguments() `
11
+ * Added new methods to ` selenium-webdriver/firefox.Options ` :
12
+ - addArguments()
13
+ - headless()
14
+ - windowSize()
12
15
* Deprecated ` selenium-webdriver/firefox/binary.Binary `
13
16
* Removed ` selenium-webdriver/firefox.Options#useGeckoDriver() `
14
17
* Removed the unused ` selenium-webdriver/firefox/profile.decode() `
Original file line number Diff line number Diff line change 16
16
// under the License.
17
17
18
18
/**
19
- * @fileoverview An example of running Chrome in headless mode.
19
+ * @fileoverview An example of running Chrome or Firefox in headless mode.
20
20
*
21
- * Before running this script , ensure you have Chrome 59+ installed and that
21
+ * To run with Chrome , ensure you have Chrome 59+ installed and that
22
22
* chromedriver 2.30+ is present on your system PATH:
23
23
* <https://sites.google.com/a/chromium.org/chromedriver/downloads>
24
24
*
25
- * Usage:
26
- * node selenium-webdriver/example/chrome_headless.js
25
+ * SELENIUM_BROWSER=chrome node selenium-webdriver/example/headless.js
26
+ *
27
+ * To run with Firefox, ensure you have Firefox 57+ installed and that
28
+ * geckodriver 0.19.0+ is present on your system PATH:
29
+ * <https://github.com/mozilla/geckodriver/releases>
30
+ *
31
+ * SELENIUM_BROWSER=firefox node selenium-webdriver/example/headless.js
27
32
*/
28
33
29
34
const chrome = require ( '../chrome' ) ;
35
+ const firefox = require ( '../firefox' ) ;
30
36
const { Builder, By, Key, until} = require ( '..' ) ;
31
37
32
38
const width = 640 ;
@@ -36,6 +42,8 @@ let driver = new Builder()
36
42
. forBrowser ( 'chrome' )
37
43
. setChromeOptions (
38
44
new chrome . Options ( ) . headless ( ) . windowSize ( { width, height} ) )
45
+ . setFirefoxOptions (
46
+ new firefox . Options ( ) . headless ( ) . windowSize ( { width, height} ) )
39
47
. build ( ) ;
40
48
41
49
driver . get ( 'http://www.google.com/ncr' )
Original file line number Diff line number Diff line change @@ -170,6 +170,35 @@ class Options {
170
170
return this ;
171
171
}
172
172
173
+ /**
174
+ * Configures the geckodriver to start Firefox in headless mode.
175
+ *
176
+ * @return {!Options } A self reference.
177
+ */
178
+ headless ( ) {
179
+ return this . addArguments ( '-headless' ) ;
180
+ }
181
+
182
+ /**
183
+ * Sets the initial window size when running in
184
+ * {@linkplain #headless headless} mode.
185
+ *
186
+ * @param {{width: number, height: number} } size The desired window size.
187
+ * @return {!Options } A self reference.
188
+ * @throws {TypeError } if width or height is unspecified, not a number, or
189
+ * less than or equal to 0.
190
+ */
191
+ windowSize ( { width, height} ) {
192
+ function checkArg ( arg ) {
193
+ if ( typeof arg !== 'number' || arg <= 0 ) {
194
+ throw TypeError ( 'Arguments must be {width, height} with numbers > 0' ) ;
195
+ }
196
+ }
197
+ checkArg ( width ) ;
198
+ checkArg ( height ) ;
199
+ return this . addArguments ( `--window-size=${ width } ,${ height } ` ) ;
200
+ }
201
+
173
202
/**
174
203
* Sets the profile to use. The profile may be specified as a
175
204
* {@link Profile} object or as the path to an existing Firefox profile to use
You can’t perform that action at this time.
0 commit comments