Skip to content

Instantly share code, notes, and snippets.

@ryancat
Last active March 12, 2018 19:51
Show Gist options
  • Save ryancat/c0a500c076f05a14cb879819adafeadb to your computer and use it in GitHub Desktop.
Save ryancat/c0a500c076f05a14cb879819adafeadb to your computer and use it in GitHub Desktop.
webdriverjs tests locally and use sauce labs to run remotely
const {Builder, By, Key, until, remote} = require('selenium-webdriver');
const sauceUsername = process.env.SAUCELABS_USER,
sauceApiToken = process.env.SAUCELABS_APITOKEN;
(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();
}
})();
(async function remoteTestExample () {
let driver = await new Builder()
.withCapabilities({
'browserName': 'chrome',
// 'platform': 'Windows XP',
// 'version': '43.0',
'username': sauceUsername,
'accessKey': sauceApiToken
})
.usingServer("http://" + sauceUsername + ":" + sauceApiToken + "@ondemand.saucelabs.com:80/wd/hub")
.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);
await driver.sleep(3000);
} finally {
await driver.quit();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment