Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akshay-bhardwaj/8871189 to your computer and use it in GitHub Desktop.
Save akshay-bhardwaj/8871189 to your computer and use it in GitHub Desktop.
/*
* Copyright Akshay Bhardway, 2014
* Node.js wd browserstack sample with screenshot taking and saving it locally
*/
var webdriver = require('wd')
, assert = require('assert')
, colors = require('colors')
, fs = require('fs');
var browser = webdriver.remote(
"hub.browserstack.com"
, 80
);
browser.on('status', function(info){
console.log(info.cyan);
});
browser.on('command', function(meth, path, data){
console.log(' < ' + meth.yellow, path.green, data || '');
});
var desired = {
browserName: 'chrome'
, version: '22.0'
, platform: 'WINDOWS'
, name: "This is an example test"
, 'browserstack.user': '<user-name>'
, 'browserstack.key': '<access-key>'
};
browser.init(desired, function() {
browser.get("http://www.google.com", function() {
browser.title(function(err, title) {
browser.elementByName('q', function(err, el) {
el.sendKeys("BrowserStack", function() {
browser.elementByName("btnG", function(err,el) {
el.click(function() {
browser.takeScreenshot(function(err, res){
data = new Buffer(res, 'base64');
fdr = fs.openSync("hello.png", 'w');
fs.writeSync(fdr,data,0,data.length);
browser.quit();
})
})
})
})
})
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment