Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
phantomjs testing script to evaluate a page, wait for a response from MathJax, and close the page. Use in conjunction with mathjax_test.js script; all this does is load the page so any errors flagged from the mathjax_test code is posted to the error database. the two scripts need each other in order to test the file. This script expects a single…
var url = require('system').args[1];
var page = require('webpage').create();
function waitFor(testFn, onSuccessFn, timeOut) {
var start = new Date().getTime();
var condition = false;
var interval = setInterval(function() {
if ( (new Date().getTime() - start < timeOut) && !condition ) {
condition = testFn();
} else {
if(!condition) {
console.log("ERROR: timeout");
phantom.exit(1);
} else {
onSuccessFn();
clearInterval(interval);
}
}
}, 250);
}
function mathJaxEvaluate() {
if (page.evaluate(function(){
return document.querySelector('#MathJax_Message');
})) {
return true;
} else {
return false;
}
}
function closeExit() {
page.close();
phantom.exit();
}
setTimeout(function() {page.open(url);}, 500);
page.onLoadFinished = function(status) {
waitFor(mathJaxEvaluate, closeExit, 6000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.