Skip to content

Instantly share code, notes, and snippets.

@lloyd
Created November 15, 2012 23:42
Show Gist options
  • Save lloyd/4082429 to your computer and use it in GitHub Desktop.
Save lloyd/4082429 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var webdriver = require('wd');
browser = webdriver.remote();
browser.on('status', function(info){
console.log('\x1b[36m%s\x1b[0m', info);
});
browser.on('command', function(meth, path){
console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path);
});
function check(err) {
if (err) {
console.log("FATAL ERROR:", err);
process.exit(1);
}
}
browser.init({}, function() {
browser.setImplicitWaitTimeout(5000, function(err) {
check(err);
browser.get("http://people.mozilla.org/~lhilaiel/hang/", function(err) {
check(err);
// 1: open a dialog
browser.elementById("theButton", function(err, elem) {
check(err);
browser.clickElement(elem, function(err) {
check(err);
browser.window("mypopup", function(err) {
check(err);
// 2: interact with it
browser.elementById("#foo", function(err, elem) {
check(err);
// 3. window closes itself WHILE WE'RE LOOKING FOR AN ELEMENT WITH EXPLICIT WAIT SET
// 4. try to find an element in the dialog
browser.elementById("foo", console.log);
});
});
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment