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);