source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/run-jasmine.coffee@ 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: 2.3 KB
Line 
1system = 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##
15waitFor = (testFx, onReady, timeOutMillis=3000) ->
16 start = new Date().getTime()
17 condition = false
18 f = ->
19 if (new Date().getTime() - start < timeOutMillis) and not condition
20 # If not time-out yet and condition not yet fulfilled
21 condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
22 else
23 if not condition
24 # If condition still not fulfilled (timeout but condition is 'false')
25 console.log "'waitFor()' timeout"
26 phantom.exit 1
27 else
28 # Condition fulfilled (timeout and/or condition is 'true')
29 console.log "'waitFor()' finished in #{new Date().getTime() - start}ms."
30 if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
31 clearInterval interval #< Stop this interval
32 interval = setInterval f, 100 #< repeat check every 100ms
33
34if system.args.length isnt 2
35 console.log 'Usage: run-jasmine.coffee URL'
36 phantom.exit 1
37
38page = require('webpage').create()
39
40# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
41page.onConsoleMessage = (msg) ->
42 console.log msg
43
44page.open system.args[1], (status) ->
45 if status isnt 'success'
46 console.log 'Unable to access network'
47 phantom.exit()
48 else
49 waitFor ->
50 page.evaluate ->
51 if document.body.querySelector '.finished-at'
52 return true
53 return false
54 , ->
55 page.evaluate ->
56 console.log document.body.querySelector('.description').innerText
57 list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage')
58 for el in list
59 console.log el.innerText
60
61 phantom.exit()
Note: See TracBrowser for help on using the repository browser.