Skip to content

Instantly share code, notes, and snippets.

@ObjectIsAdvantag
Last active December 2, 2015 21:21
Show Gist options
  • Save ObjectIsAdvantag/3823bc252921f3bbc630 to your computer and use it in GitHub Desktop.
Save ObjectIsAdvantag/3823bc252921f3bbc630 to your computer and use it in GitHub Desktop.
Horseman UI testing sample
/*
* UI testing with Horseman (phantomjs node integration)
*
* Installation
* see http://www.horsemanjs.org/
*
* Run
* node <this-file.js>
*
* Debugging
* set DEBUG to horseman to get insight about what's going on
*
* Trace sample
horseman .setup() creating phantom instance on +0ms
horseman .setup() phantom instance created ok. +872ms
horseman .setup() creating phantom page. +3ms
horseman .setup() phantom page created ok. +22ms
horseman .setup() setting viewport. +2ms
horseman .setup() viewport set ok. +10ms
horseman .opening: http://restlet.com/products/apispark/ +37ms
horseman load finished, injecting jquery and client scripts +6s
horseman .open: http://restlet.com/products/apispark/ - status: success +4ms
horseman jQuery not injected - already exists on page +7ms
horseman .click() a#apispark_signin_1 +113ms
horseman .waitForSelector() div.a0-notloggedin.a0-mode +2s
horseman .type() steve.sfartz@gmail.com into input[name="email"] +63ms
horseman .type() XXXXXXXX into input[name="password"] +123ms
horseman .click() button.a0-primary.a0-next +63ms
horseman .waitForSelector() a.dropdown-toggle.ng-binding +7s
horseman .url() +2ms
horseman .evaluate() fn on the page +59ms
horseman .close(). +3ms
*
*/
var horsemanModule = require("node-horseman");
// Increase timeout from 5s to 20s so that APISpark home can load
var horseman = new horsemanModule ({ 'timeout' : 20000 });
var result = horseman.open('http://restlet.com/products/apispark/')
.click('a#apispark_signin_1')
// wait for auth0 div to by displayed
.waitForSelector('div.a0-notloggedin.a0-mode')
// login via a test account (rather than a social provider)
.type('input[name="email"]','steve.sfartz@gmail.com')
.type('input[name="password"]','XXXXXXXX')
.click('button.a0-primary.a0-next')
// wait to dashboard to appear
.waitForSelector('a.dropdown-toggle.ng-binding')
.url();
horseman.close();
console.log(result);
// => https://apispark.restlet.com/dashboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment