Skip to content

Commit

Permalink
[js] Make sure examples are all updated for #2969
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Nov 2, 2016
1 parent fe03c57 commit 6fa3c01
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 82 deletions.
31 changes: 18 additions & 13 deletions javascript/node/selenium-webdriver/example/chrome_android.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@
* AVD).
*/

var webdriver = require('..'),
By = webdriver.By,
until = webdriver.until,
chrome = require('../chrome');
'use strict';

var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().androidChrome())
.build();
const {Builder, By, promise, until} = require('..');
const {Options} = require('../chrome');

driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
promise.consume(function* () {
let driver;
try {
driver = yield new Builder()
.forBrowser('chrome')
.setChromeOptions(new Options().androidChrome())
.build();
yield driver.get('http://www.google.com/ncr');
yield driver.findElement(By.name('q')).sendKeys('webdriver');
yield driver.findElement(By.name('btnG')).click();
yield driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
yield driver && driver.quit();
}
}).then(_ => console.log('SUCCESS'), err => console.error('ERROR: ' + err));
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
* ChromeDriver.
*/

var webdriver = require('..'),
By = webdriver.By,
until = webdriver.until,
chrome = require('../chrome');
'use strict';

const {Builder, By, promise, until} = require('..');
const {Options} = require('../chrome');

var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.setMobileEmulation({deviceName: 'Google Nexus 5'}))
.build();

driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
promise.consume(function* () {
let driver;
try {
driver = yield new Builder()
.forBrowser('chrome')
.setChromeOptions(
new Options().setMobileEmulation({deviceName: 'Google Nexus 5'}))
.build();
yield driver.get('http://www.google.com/ncr');
yield driver.findElement(By.name('q')).sendKeys('webdriver');
yield driver.findElement(By.name('btnG')).click();
yield driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
yield driver && driver.quit();
}
}).then(_ => console.log('SUCCESS'), err => console.error('ERROR: ' + err));
6 changes: 4 additions & 2 deletions javascript/node/selenium-webdriver/example/google_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
// under the License.

/**
* @fileoverview An example WebDriver script. This requires the chromedriver
* to be present on the system PATH.
* @fileoverview An example WebDriver script.
*
* Before running this script, ensure that Mozilla's geckodriver is present on
* your system PATH: <https://github.com/mozilla/geckodriver/releases>
*
* Usage:
* // Default behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,33 @@
/**
* @fileoverview An example WebDriver script using generator functions.
*
* Usage: node selenium-webdriver/example/google_search_generator.js
* Before running this script, ensure that Mozilla's geckodriver is present on
* your system PATH: <https://github.com/mozilla/geckodriver/releases>
*
* Usage:
*
* node selenium-webdriver/example/google_search_generator.js
*/

var webdriver = require('..'),
By = webdriver.By;
'use strict';

const {Builder, By, promise, until} = require('..');

var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
promise.consume(function* () {
let driver;
try {
driver = yield new Builder().forBrowser('firefox').build();

driver.get('http://www.google.com/ncr');
driver.call(function* () {
var query = yield driver.findElement(By.name('q'));
query.sendKeys('webdriver');
yield driver.get('http://www.google.com/ncr');

var submit = yield driver.findElement(By.name('btnG'));
submit.click();
});
let q = yield driver.findElement(By.name('q'));
yield q.sendKeys('webdriver');

driver.wait(function* () {
var title = yield driver.getTitle();
return 'webdriver - Google Search' === title;
}, 1000);
let btnG = yield driver.findElement(By.name('btnG'));
yield btnG.click();

driver.quit();
yield driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
yield driver && driver.quit();
}
}).then(_ => console.log('SUCCESS'), err => console.error('ERROR: ' + err));
48 changes: 31 additions & 17 deletions javascript/node/selenium-webdriver/example/google_search_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,45 @@

/**
* @fileoverview An example test that may be run using Mocha.
* Usage: mocha -t 10000 selenium-webdriver/example/google_search_test.js
*
* Usage:
*
* mocha -t 10000 selenium-webdriver/example/google_search_test.js
*
* You can change which browser is started with the SELENIUM_BROWSER environment
* variable:
*
* SELENIUM_BROWSER=chrome \
* mocha -t 10000 selenium-webdriver/example/google_search_test.js
*/

var webdriver = require('..'),
By = webdriver.By,
until = webdriver.until,
test = require('../testing');
const {Builder, By, until} = require('..');
const test = require('../testing');

test.describe('Google Search', function() {
var driver;
let driver;

test.before(function() {
driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
test.before(function *() {
driver = yield new Builder().forBrowser('firefox').build();
});

test.it('should append query to title', function() {
driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
// You can write tests either using traditional promises.
it('works with promises', function() {
return driver.get('http://www.google.com')
.then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
.then(_ => driver.findElement(By.name('btnG')).click())
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000));
});

test.after(function() {
driver.quit();
// Or you can define the test as a generator function. The test will wait for
// any yielded promises to resolve before invoking the next step in the
// generator.
test.it('works with generators', function*() {
yield driver.get('http://www.google.com/ncr');
yield driver.findElement(By.name('q')).sendKeys('webdriver');
yield driver.findElement(By.name('btnG')).click();
yield driver.wait(until.titleIs('webdriver - Google Search'), 1000);
});

test.after(() => driver.quit());
});
26 changes: 9 additions & 17 deletions javascript/node/selenium-webdriver/example/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@

'use strict';

var webdriver = require('..'),
By = webdriver.By,
until = webdriver.until;
const {Builder, By, logging, until} = require('..');

webdriver.logging.installConsoleHandler();
webdriver.logging.getLogger('webdriver.http')
.setLevel(webdriver.logging.Level.ALL);
logging.installConsoleHandler();
logging.getLogger('webdriver.http').setLevel(logging.Level.ALL);

var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
var driver = new Builder().forBrowser('firefox').build();

driver.get('http://www.google.com/ncr');

var searchBox = driver.wait(until.elementLocated(By.name('q')), 3000);
searchBox.sendKeys('webdriver');

driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
driver.get('http://www.google.com/ncr')
.then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
.then(_ => driver.findElement(By.name('btnG')).click())
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(_ => driver.quit());
3 changes: 3 additions & 0 deletions javascript/node/selenium-webdriver/example/parallel_flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
/**
* @fileoverview An example of starting multiple WebDriver clients that run
* in parallel in separate control flows.
*
* This example will only work when the promise manager is enabled
* (see <https://github.com/SeleniumHQ/selenium/issues/2969>).
*/

var webdriver = require('..'),
Expand Down

0 comments on commit 6fa3c01

Please sign in to comment.