Created
June 23, 2016 10:06
-
-
Save nabinno/a121286892c3ecbf6eea74ea905ba4d9 to your computer and use it in GitHub Desktop.
PhantomJS
This file contains 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 page = require('webpage').create(); | |
var system = require('system'); | |
if (system.args.length === 1) { | |
console.log('Usage: phatomjs warmup-select-condition.js <some URL>'); | |
phantom.exit(); | |
} | |
var address = system.args[1]; | |
var lib = "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"; | |
page.onConsoleMessage = function(msg) { console.log("console> " + msg); } | |
page.open(address, function(status) { | |
if (status !== 'success') { | |
console.log('FAIL to warm up the address'); | |
} else { | |
var t = Date.now(); | |
setTimeout(function() { | |
page.includeJs(lib, function() { | |
console.log('----------------------------------------------------------------------'); | |
page.evaluate(function() { | |
console.log("show_title: " + $("title").text()); | |
console.log("show_button: " + $("button").text()); | |
$("button").click(); | |
}); | |
console.log("time: " + (Date.now() - t) + "ms"); | |
}); | |
}, 0); | |
setTimeout(function() { | |
page.includeJs(lib, function() { | |
console.log('----------------------------------------------------------------------'); | |
page.evaluate(function() { | |
console.log("show_title: " + $("title").text()); | |
console.log("show_button: " + $("button").text()); | |
$("button").click(); | |
}); | |
console.log("time: " + (Date.now() - t) + "ms"); | |
phantom.exit(); | |
}); | |
}, 3000); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment