source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/run-qunit.js@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 3.0 KB
Line 
1var system = require('system');
2
3/**
4 * Wait until the test condition is true or a timeout occurs. Useful for waiting
5 * on a server response or for a ui change (fadeIn, etc.) to occur.
6 *
7 * @param testFx javascript condition that evaluates to a boolean,
8 * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
9 * as a callback function.
10 * @param onReady what to do when testFx condition is fulfilled,
11 * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
12 * as a callback function.
13 * @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
14 */
15function waitFor(testFx, onReady, timeOutMillis) {
16 var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timout is 3s
17 start = new Date().getTime(),
18 condition = false,
19 interval = setInterval(function() {
20 if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
21 // If not time-out yet and condition not yet fulfilled
22 condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
23 } else {
24 if(!condition) {
25 // If condition still not fulfilled (timeout but condition is 'false')
26 console.log("'waitFor()' timeout");
27 phantom.exit(1);
28 } else {
29 // Condition fulfilled (timeout and/or condition is 'true')
30 console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
31 typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
32 clearInterval(interval); //< Stop this interval
33 }
34 }
35 }, 100); //< repeat check every 250ms
36};
37
38
39if (system.args.length !== 2) {
40 console.log('Usage: run-qunit.js URL');
41 phantom.exit(1);
42}
43
44var page = require('webpage').create();
45
46// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
47page.onConsoleMessage = function(msg) {
48 console.log(msg);
49};
50
51page.open(system.args[1], function(status){
52 if (status !== "success") {
53 console.log("Unable to access network");
54 phantom.exit(1);
55 } else {
56 waitFor(function(){
57 return page.evaluate(function(){
58 var el = document.getElementById('qunit-testresult');
59 if (el && el.innerText.match('completed')) {
60 return true;
61 }
62 return false;
63 });
64 }, function(){
65 var failedNum = page.evaluate(function(){
66 var el = document.getElementById('qunit-testresult');
67 console.log(el.innerText);
68 try {
69 return el.getElementsByClassName('failed')[0].innerHTML;
70 } catch (e) { }
71 return 10000;
72 });
73 phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
74 });
75 }
76});
Note: See TracBrowser for help on using the repository browser.