-
Notifications
You must be signed in to change notification settings - Fork 1
/
phantomTestRunner.js
67 lines (56 loc) · 1.91 KB
/
phantomTestRunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Little phantomjs script that opens a list of urls given
* in the first argument as a comma-separated list.
* Intended for running YUI test suites that callback to
* phantom at test completion via:
*
* <pre>
* if ( typeof( window.callPhantom ) != 'undefined' ) {
* // phantomjs environment!
* console.log( "Phantomjs detected!" );
* Y.Test.Runner.subscribe( Y.Test.Runner.COMPLETE_EVENT, window.callPhantom );
* }
*
* </pre>
*/
var system = require( 'system' );
if ( (system.args.length < 2) || system.args[1].match( /^-+/ ) ) {
// use comma-separated list - easier to integrate with ant that way
console.log( "script takes exactly one argument: a comma-separated list of test urls" );
phantom.exit(1);
}
var urlList = system.args[1].split( /,+/ );
/*
for ( var i = 1; i < system.args.length; ++i ) {
urlList.push( system.args[i] );
}
*/
var resultList = [];
var currentTest = 0;
var page = require( 'webpage' ).create();
page.onConsoleMessage = function(msg) { console.log( msg ); };
function runTest( url ) {
page.open( url,
function( status ) {
console.log( url + " status: " + status );
if ( status != "success" ) {
phantom.exit(1);
}
page.evaluate( function() { console.log( "page location: " + window.location.href ); } );
}
);
}
page.onCallback = function( testResult ) {
resultList.push( testResult );
currentTest += 1;
if ( currentTest < urlList.length ) {
runTest( urlList[currentTest] );
} else {
console.log( "-------------------------------------------------------------" );
console.log( "-------------------------------------------------------------" );
console.log( resultList.length + " Tests complete: " );
console.log( JSON.stringify( resultList ) );
phantom.exit( 0 );
}
};
runTest( urlList[0] );