Skip to content

Instantly share code, notes, and snippets.

@DylanLacey
Created September 25, 2018 07:18
Show Gist options
  • Save DylanLacey/4e55ecbd911283cf1d2d79365cc485b7 to your computer and use it in GitHub Desktop.
Save DylanLacey/4e55ecbd911283cf1d2d79365cc485b7 to your computer and use it in GitHub Desktop.
Several Node Examples
const webdriver = require("selenium-webdriver");
username = process.env.SAUCE_USERNAME;
accessKey = process.env.SAUCE_ACCESS_KEY;
driver = new webdriver.Builder().withCapabilities({
'browserName': 'Chrome',
'platform': 'Windows 7',
'version': '68'
}).
usingServer("https://" + username + ":" + accessKey +
"@ondemand.saucelabs.com:443/wd/hub").
build();
session_id = null;
passing = false;
driver.getSession().then(function (session) {
console.log('SauceOnDemandSessionID=' + session.getId() + ' job-name=SauceLabsTest');
session_id = session.getId();
}).then(function () {
driver.get("https://www.google.com");
driver.getTitle().then(function (title) {
passing = (title == "I am a page title - Sauce Labs");
console.log("title is: " + title);
});
}).then(function () {
driver.quit();
driver.getSession().then(function (session) {
const exec = require('child_process').execSync;
var cmd = "curl -X PUT -s -d '{\"passed\": " +
passing +
"}' -u " +
username +
":" +
accessKey +
" https://saucelabs.com/rest/v1/" +
username +
"/jobs/" +
session.getId();
exec(cmd);
});
});
const webdriver = require("selenium-webdriver");
username = process.env.SAUCE_USERNAME;
accessKey = process.env.SAUCE_ACCESS_KEY;
driver = new webdriver.Builder().withCapabilities({
'browserName': 'Chrome',
'platform': 'Windows 7',
'version': '68'
}).
usingServer("https://" + username + ":" + accessKey +
"@ondemand.saucelabs.com:443/wd/hub").
build();
session_id = null;
passing = false;
driver.getSession().then(function (session) {
console.log('SauceOnDemandSessionID=' + session.getId() + ' job-name=SauceLabsTest');
session_id = session.getId();
}).then(function () {
driver.get("https://saucelabs.com/test/guinea-pig");
driver.getTitle().then(function (title) {
passing = (title == "I am a page title - Sauce Labs");
console.log("title is: " + title);
});
}).then(function () {
driver.quit();
driver.getSession().then(function (session) {
const exec = require('child_process').execSync;
var cmd = "curl -X PUT -s -d '{\"passed\": " +
passing +
"}' -u " +
username +
":" +
accessKey +
" https://saucelabs.com/rest/v1/" +
username +
"/jobs/" +
session.getId();
exec(cmd);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment