Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function waitFor(testFx, onReady, timeOutMillis) {
- var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, //< Default Max Timout is 3s
- start = new Date().getTime(),
- condition = false,
- interval = setInterval(function() {
- if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
- // If not time-out yet and condition not yet fulfilled
- condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
- } else {
- if(!condition) {
- // If condition still not fulfilled (timeout but condition is 'false')
- console.log("'waitFor()' timeout");
- phantom.exit(1);
- } else {
- // Condition fulfilled (timeout and/or condition is 'true')
- console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
- typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
- clearInterval(interval); //< Stop this interval
- }
- }
- }, 250); //< repeat check every 250ms
- };
- var page = require('webpage').create(),
- system = require('system'),
- t, address;
- if (system.args.length === 1) {
- console.log('Usage: loadspeed.js <some URL>');
- phantom.exit();
- }
- t = Date.now();
- address = system.args[1];
- page.open(address, function(status) {
- if (status !== 'success') {
- console.log('FAIL to load the address');
- } else {
- t = Date.now() - t;
- console.log('Loading time ' + t + ' msec');
- waitFor(function() {
- var btn = page.evaluate(function() {
- return Ext.getCmp('export_to_excel_btn');
- });
- return btn !== null;
- },
- function() {
- var xl;
- waitFor(function() {
- xl = page.evaluate(function() {
- var btn = Ext.getCmp('export_to_excel_btn');
- return btn.handler(); // Never works.
- });
- console.log(xl)
- return xl !== null;
- },
- function() {
- console.log('In the inner waitFor');
- phantom.exit();
- }, 10000);
- }, 10000);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement