Skip to content

Instantly share code, notes, and snippets.

@joubertnel
Created October 31, 2011 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joubertnel/1327495 to your computer and use it in GitHub Desktop.
Save joubertnel/1327495 to your computer and use it in GitHub Desktop.
PhantomJS script for test automation of SproutCore app
var allTestsURL = "http://localhost:4020/reader_core/en/current/tests.html";
var failedItem;
var failureCount;
var failureMessage;
var failures;
var i, j;
var reportingDone = false;
var specDescription;
var specs;
if (phantom.state.length === 0) {
console.log('PhantomJS - setting up and starting tests.');
phantom.viewportSize = { width:1024, height:768 };
phantom.state = 'opening';
phantom.open(allTestsURL);
} else {
window.setInterval(function() {
if (reportingDone === false) {
if (document.querySelector('div.runner.passed')) {
reportingDone = true;
phantom.exit(0);
}
if (document.querySelector('div.runner.failed')) {
failures = document.querySelectorAll('div.spec.failed');
console.log('failure count=' + failures.length);
failureCount = failures.length;
for (i=0; i < failureCount; i++) {
console.log('Failure #' + i);
failedItem = failures[i];
specDescription = failedItem.querySelector('a.description').attributes['title'].value;
console.log(specDescription);
failureMessage = failedItem.querySelector('div.messages').innerText;
console.log(' ' + failureMessage);
}
reportingDone = true;
phantom.exit(1);
}
}
}, 100);
}
@umarsheikh
Copy link

I tried running this, but it crashes on line 11 with
undefined:11 TypeError: Result of expression 'phantom.state' [undefined] is not an object.
i am still new to this, so how can i modify the above script to run the tests and parse the results successfully?

@ariya
Copy link

ariya commented Jan 18, 2012

This is using phantom.state, a horribly outdated API that was gone long time ago (see http://code.google.com/p/phantomjs/wiki/ReleaseNotes#PhantomJS_1.2_"Birds_of_Paradise") for details.

For the new approach, consider using the example given in http://code.google.com/p/phantomjs/wiki/TestFrameworkIntegration.

@joubertnel
Copy link
Author

Thanks for pointing that out, ariya!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment