Skip to content

Instantly share code, notes, and snippets.

@cjerdonek
Created August 31, 2014 01:48
Show Gist options
  • Save cjerdonek/30278f7f7b34baa2ae37 to your computer and use it in GitHub Desktop.
Save cjerdonek/30278f7f7b34baa2ae37 to your computer and use it in GitHub Desktop.
Javascript example of using Selenium WebDriver's Javascript API to connect to Sauce Labs
// This is an example of using the Selenium WebDriver's Javascript API
// to connect to Sauce Labs (using the remote web driver) and doing
// a simple test.
//
// To run from the command-line:
//
// $ node drive.js
//
// You need to have selenium-webdriver installed with npm.
// For javascript API docs:
//
// http://selenium.googlecode.com/git/docs/api/javascript/namespace_webdriver.html
//
// For another example using Sauce Labs:
//
// http://stackoverflow.com/questions/21170734/how-can-i-use-selenium-webdriver-package-with-saucelabs
var webdriver = require('selenium-webdriver');
var sauce = 'http://ondemand.saucelabs.com:80/wd/hub';
var driver = new webdriver.Builder().
usingServer(sauce).
withCapabilities({
name: 'Firefox test',
browserName: 'firefox',
version: '31',
'selenium-version': '2.42.1',
platform: 'linux',
username: '***',
accessKey: '***'
}).
build();
driver.get('http://cjerdonek.github.io/quick-sampler/#/');
var el = driver.findElement(webdriver.By.id('id_total_count'));
el.sendKeys('100');
el.getAttribute("value").then(function(value) {
console.log('value: "' + value + '"');
});
driver.quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment