Skip to content

Commit

Permalink
Syntax highlighting for JavasScript examples (SeleniumHQ#5364)
Browse files Browse the repository at this point in the history
Uses the GitHub syntax highlighting for the readme.md
  • Loading branch information
Chris Ward authored and jleyba committed Jan 18, 2018
1 parent 92d2aee commit a1472bc
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions javascript/node/selenium-webdriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ Safari 10 before testing.
The sample below and others are included in the `example` directory. You may
also find the tests for selenium-webdriver informative.

const {Builder, By, Key, until} = require('selenium-webdriver');

(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
await driver.quit();
}
})();
```javascript
const {Builder, By, Key, until} = require('selenium-webdriver');

(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
await driver.quit();
}
})();
```

### Using the Builder API

Expand All @@ -51,15 +53,17 @@ instances. Rather than clutter your code with branches for the various browsers,
the builder lets you set all options in one flow. When you call
`Builder#build()`, all options irrelevant to the selected browser are dropped:

const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const firefox = require('selenium-webdriver/firefox');
```javascript
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const firefox = require('selenium-webdriver/firefox');

let driver = new webdriver.Builder()
.forBrowser('firefox')
.setChromeOptions(/* ... */)
.setFirefoxOptions(/* ... */)
.build();
let driver = new webdriver.Builder()
.forBrowser('firefox')
.setChromeOptions(/* ... */)
.setFirefoxOptions(/* ... */)
.build();
```

Why would you want to configure options irrelevant to the target browser? The
`Builder`'s API defines your _default_ configuration. You can change the target
Expand Down Expand Up @@ -92,11 +96,12 @@ server with
You may configure your tests to run against a remote server through the Builder
API:

let driver = new webdriver.Builder()
.forBrowser('firefox')
.usingServer('http://localhost:4444/wd/hub')
.build();

```javascript
let driver = new webdriver.Builder()
.forBrowser('firefox')
.usingServer('http://localhost:4444/wd/hub')
.build();
```
Or change the Builder's configuration at runtime with the `SELENIUM_REMOTE_URL`
environment variable:

Expand Down

0 comments on commit a1472bc

Please sign in to comment.