@@ -31,18 +31,20 @@ Safari 10 before testing.
3131The sample below and others are included in the ` example ` directory. You may
3232also find the tests for selenium-webdriver informative.
3333
34- const {Builder, By, Key, until} = require('selenium-webdriver');
35-
36- (async function example() {
37- let driver = await new Builder().forBrowser('firefox').build();
38- try {
39- await driver.get('http://www.google.com/ncr');
40- await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
41- await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
42- } finally {
43- await driver.quit();
44- }
45- })();
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+ ```
4648
4749### Using the Builder API
4850
@@ -51,15 +53,17 @@ instances. Rather than clutter your code with branches for the various browsers,
5153the builder lets you set all options in one flow. When you call
5254` Builder#build() ` , all options irrelevant to the selected browser are dropped:
5355
54- const webdriver = require('selenium-webdriver');
55- const chrome = require('selenium-webdriver/chrome');
56- const firefox = require('selenium-webdriver/firefox');
56+ ``` javascript
57+ const webdriver = require (' selenium-webdriver' );
58+ const chrome = require (' selenium-webdriver/chrome' );
59+ const firefox = require (' selenium-webdriver/firefox' );
5760
58- let driver = new webdriver.Builder()
59- .forBrowser('firefox')
60- .setChromeOptions(/* ... */)
61- .setFirefoxOptions(/* ... */)
62- .build();
61+ let driver = new webdriver.Builder ()
62+ .forBrowser (' firefox' )
63+ .setChromeOptions (/* ... */ )
64+ .setFirefoxOptions (/* ... */ )
65+ .build ();
66+ ```
6367
6468Why would you want to configure options irrelevant to the target browser? The
6569` Builder ` 's API defines your _ default_ configuration. You can change the target
@@ -92,11 +96,12 @@ server with
9296You may configure your tests to run against a remote server through the Builder
9397API:
9498
95- let driver = new webdriver.Builder()
96- .forBrowser('firefox')
97- .usingServer('http://localhost:4444/wd/hub')
98- .build();
99-
99+ ``` javascript
100+ let driver = new webdriver.Builder ()
101+ .forBrowser (' firefox' )
102+ .usingServer (' http://localhost:4444/wd/hub' )
103+ .build ();
104+ ```
100105Or change the Builder's configuration at runtime with the ` SELENIUM_REMOTE_URL `
101106environment variable:
102107
0 commit comments