Skip to content

Instantly share code, notes, and snippets.

@n1k0
Created July 4, 2012 08:46
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save n1k0/3046142 to your computer and use it in GitHub Desktop.
Save n1k0/3046142 to your computer and use it in GitHub Desktop.
PhantomJS test script for window.location
var page = require('webpage').create();
var base = phantom.args[0];
var path = phantom.args[1];
var expected = phantom.args[2];
page.onNavigationRequested = function(url, navigationType, navigationLocked, isMainFrame) {
console.log('Navigation requested: ' + navigationType + '; ' + url);
if (!page.testStarted) {
return;
}
if (url === expected) {
console.log('PASS');
phantom.exit();
}
};
page.open(base, function(status) {
page.testStarted = true;
console.log('window.location = ' + path);
page.evaluate(function(path) {
window.location = path;
}, path);
});
setTimeout(function() {
console.log('FAIL: navigation to ' + path + ' never happened');
phantom.exit(1);
}, 5000);
@janko
Copy link

janko commented Apr 19, 2014

Yeah, just tried with PhantomJS 1.9.7 (with google.com and github.com), and it indeed doesn't work. Do you have an idea how to get around this?

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