Last active
March 12, 2018 19:51
-
-
Save ryancat/c0a500c076f05a14cb879819adafeadb to your computer and use it in GitHub Desktop.
webdriverjs tests locally and use sauce labs to run remotely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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