Created
August 21, 2013 14:07
-
-
Save tiarno/6294913 to your computer and use it in GitHub Desktop.
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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