Skip to content

Instantly share code, notes, and snippets.

@nsbingham
Created September 3, 2013 13:36
Show Gist options
  • Save nsbingham/6424018 to your computer and use it in GitHub Desktop.
Save nsbingham/6424018 to your computer and use it in GitHub Desktop.
A comparison of using wd.js with callbacks versus the promises API
// Example of nesting wd.js callbacks
browser.get("http://admc.io/wd/test-pages/guinea-pig.html", function() {
browser.title(function(err, title) {
assert.ok(~title.indexOf('I am a page title - Sauce Labs'), 'Wrong title!');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
browser.eval("window.location.href", function(err, href) {
assert.ok(~href.indexOf('guinea-pig2'));
browser.quit();
});
});
});
});
});
// Same example using promises API
browser.get("http://admc.io/wd/test-pages/guinea-pig.html")
.then(function () {
return browser.title();
}).then(function (title) {
assert.ok(~title.indexOf('I am a page title - Sauce Labs'), 'Wrong title!');
return browser.elementById('i am a link');
}).then(function (el) {
return browser.clickElement(el);
}).then(function () {
/* jshint evil: true */
return browser.eval("window.location.href");
}).then(function (href) {
assert.ok(~href.indexOf('guinea-pig2'));
}).fin(function () {
browser.quit();
}).done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment