4faca6ac345dc4f9a0ab7fc3682575bbea2528d7.svn-base
1.08 KB
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
function waitFor(test, complete, timeout) {
var result, start = new Date().getTime()
setInterval(function interval() {
if ((new Date().getTime() - start < timeout) && !result) {
result = test()
} else {
if (!result) {
phantom.exit(1)
} else {
complete()
clearInterval(interval)
}
}
}, 100)
}
var page = new WebPage()
page.onConsoleMessage = function(msg) {
console.log(msg)
}
page.open(phantom.args[0], function(status) {
waitFor(function() {
return page.evaluate(function(){
var el = document.getElementById('qunit-testresult')
return el && el.innerText.match('completed')
})
}, function() {
var failures = page.evaluate(function() {
var el = document.getElementById('qunit-testresult'),
fails = document.getElementsByClassName('fail')
for (var i = 0; i < fails.length; i++)
console.log(fails[i].innerText)
console.log(el.innerText)
return parseInt(el.getElementsByClassName('failed')[0].innerHTML)
})
phantom.exit(failures > 0 ? 1 : 0)
}, 10000)
})