Created
August 25, 2014 21:32
-
-
Save nevir/a6f2abe2e19e040435e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var wd = require('wd'); | |
var SauceTunnel = require('sauce-tunnel'); | |
var BROWSERS = [ | |
{ | |
browserName: "internet explorer", | |
version: "11", | |
platform: "Windows 8.1" | |
}, | |
{ | |
browserName: "chrome", | |
platform: "Windows 8.1", | |
version: "36" | |
}, | |
{ | |
browserName: "firefox", | |
platform: "Windows 8.1", | |
version: "31" | |
}, | |
{ | |
browserName: "chrome", | |
platform: "OS X 10.9" | |
}, | |
{ | |
browserName: "safari", | |
platform: "OS X 10.9", | |
version: "7" | |
}, | |
{ | |
browserName: "iphone", | |
platform: "OS X 10.9", | |
version: "7.1" | |
}, | |
]; | |
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) { | |
throw new Error('Please set SAUCE_USERNAME and SAUCE_ACCESS_KEY as env vars'); | |
} | |
var user = process.env.SAUCE_USERNAME; | |
var key = process.env.SAUCE_ACCESS_KEY; | |
var tunnelId = 'Tunnel'+Date.now(); | |
var tunnel = new SauceTunnel(user, key, tunnelId, true); | |
console.log('Starting tunnel'); | |
tunnel.start(function(started) { | |
if (started) { | |
startBrowsers(); | |
} else { | |
console.log('Tunnel failed to start'); | |
} | |
}); | |
function startBrowsers() { | |
BROWSERS.forEach(function(browser) { | |
var client = wd.remote('ondemand.saucelabs.com', 80, user, key); | |
configureLogging(client); | |
browser['tunnel-identifier'] = tunnelId; | |
client.init(browser, function(error, session, result) { | |
console.log('client.init callback:', error, session, result); | |
client.get('https://google.com', function(error) { | |
console.log('client.get callback:', error); | |
client.quit(); | |
}); | |
}); | |
}); | |
} | |
function configureLogging(client) { | |
client.on('command', function(eventType, command, response) { | |
console.log('} ' + eventType, command, response); | |
}); | |
client.on('http', function(method, path, data) { | |
console.log('> ' + method, path, data); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment