phantomjs.rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. data/.autotest +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +4 -0
  4. data/README.md +16 -0
  5. data/Rakefile +1 -0
  6. data/lib/phantomjs.rb +53 -0
  7. data/lib/phantomjs/version.rb +3 -0
  8. data/phantomjs.rb.gemspec +24 -0
  9. data/spec/phantomjs_spec.rb +13 -0
  10. data/spec/runner.js +2 -0
  11. data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
  12. data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
  13. data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
  14. data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
  15. data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
  16. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
  17. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
  18. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
  19. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
  20. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
  21. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
  22. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
  23. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
  24. data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
  25. data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
  26. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
  27. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
  28. data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
  29. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
  30. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
  31. data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
  32. data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
  33. data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
  34. data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
  35. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
  36. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
  37. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
  38. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
  39. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
  40. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
  41. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
  42. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
  43. data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
  44. data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
  45. data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
  46. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
  47. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
  48. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
  49. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
  50. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
  51. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
  52. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
  53. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
  54. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
  55. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
  56. data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
  57. data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
  58. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
  59. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
  60. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
  61. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
  62. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
  63. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
  64. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
  65. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
  66. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
  67. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
  68. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
  69. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
  70. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
  71. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
  72. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
  73. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
  74. data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
  75. data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
  76. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
  77. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
  78. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
  79. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
  80. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
  81. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
  82. data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
  83. data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
  84. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
  85. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
  86. data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
  87. data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
  88. data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
  89. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
  90. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
  91. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
  92. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
  93. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
  94. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
  95. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
  96. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
  97. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
  98. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
  99. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
  100. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
  101. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
  102. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
  103. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
  104. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
  105. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
  106. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
  107. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
  108. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
  109. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
  110. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
  111. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
  112. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
  113. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
  114. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
  115. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
  116. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
  117. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
  118. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
  119. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
  120. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
  121. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
  122. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
  123. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
  124. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
  125. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
  126. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
  127. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
  128. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
  129. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
  130. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
  131. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
  132. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
  133. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
  134. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
  135. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
  136. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
  137. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
  138. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
  139. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
  140. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
  141. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
  142. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
  143. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
  144. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
  145. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
  146. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
  147. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
  148. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
  149. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
  150. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
  151. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
  152. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
  153. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
  154. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
  155. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
  156. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
  157. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
  158. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
  159. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
  160. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
  161. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
  162. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
  163. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
  164. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
  165. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
  166. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
  167. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
  168. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
  169. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
  170. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
  171. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
  172. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
  173. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
  174. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
  175. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
  176. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
  177. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
  178. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
  179. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
  180. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
  181. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
  182. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
  183. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
  184. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
  185. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
  186. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
  187. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
  188. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
  189. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
  190. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
  191. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
  192. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
  193. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
  194. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
  195. metadata +252 -0
@@ -0,0 +1,34 @@
1
+ // Example using HTTP POST operation
2
+
3
+ var page = require('webpage').create(),
4
+ server = require('webserver').create(),
5
+ system = require('system'),
6
+ data = 'universe=expanding&answer=42';
7
+
8
+ if (system.args.length !== 2) {
9
+ console.log('Usage: postserver.js <portnumber>');
10
+ phantom.exit();
11
+ }
12
+
13
+ var port = system.args[1];
14
+
15
+ service = server.listen(port, function (request, response) {
16
+ console.log('Request received at ' + new Date());
17
+
18
+ response.statusCode = 200;
19
+ response.headers = {
20
+ 'Cache': 'no-cache',
21
+ 'Content-Type': 'text/plain;charset=utf-8'
22
+ };
23
+ response.write(JSON.stringify(request, null, 4));
24
+ response.close();
25
+ });
26
+
27
+ page.open('http://localhost:' + port + '/', 'post', data, function (status) {
28
+ if (status !== 'success') {
29
+ console.log('Unable to post!');
30
+ } else {
31
+ console.log(page.plainText);
32
+ }
33
+ phantom.exit();
34
+ });
@@ -0,0 +1,10 @@
1
+ var system = require('system'),
2
+ env = system.env,
3
+ key;
4
+
5
+ for (key in env) {
6
+ if (env.hasOwnProperty(key)) {
7
+ console.log(key + '=' + env[key]);
8
+ }
9
+ }
10
+ phantom.exit();
@@ -0,0 +1,35 @@
1
+ var page = require('webpage').create(),
2
+ system = require('system');
3
+
4
+ if (system.args.length < 7) {
5
+ console.log('Usage: printmargins.js URL filename LEFT TOP RIGHT BOTTOM');
6
+ console.log(' margin examples: "1cm", "10px", "7mm", "5in"');
7
+ phantom.exit();
8
+ } else {
9
+ var address = system.args[1];
10
+ var output = system.args[2];
11
+ var marginLeft = system.args[3];
12
+ var marginTop = system.args[4];
13
+ var marginRight = system.args[5];
14
+ var marginBottom = system.args[6];
15
+ page.viewportSize = { width: 600, height: 600 };
16
+ page.paperSize = {
17
+ format: 'A4',
18
+ margin: {
19
+ left: marginLeft,
20
+ top: marginTop,
21
+ right: marginRight,
22
+ bottom: marginBottom
23
+ }
24
+ };
25
+ page.open(address, function (status) {
26
+ if (status !== 'success') {
27
+ console.log('Unable to load the address!');
28
+ } else {
29
+ window.setTimeout(function () {
30
+ page.render(output);
31
+ phantom.exit();
32
+ }, 200);
33
+ }
34
+ });
35
+ }
@@ -0,0 +1,23 @@
1
+ page = require('webpage').create()
2
+ system = require 'system'
3
+
4
+ if system.args.length < 3 or system.args.length > 4
5
+ console.log 'Usage: rasterize.coffee URL filename [paperwidth*paperheight|paperformat]'
6
+ console.log ' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'
7
+ phantom.exit()
8
+ else
9
+ address = system.args[1]
10
+ output = system.args[2]
11
+ page.viewportSize = { width: 600, height: 600 }
12
+ if system.args.length is 4 and system.args[2].substr(-4) is ".pdf"
13
+ size = system.args[3].split '*'
14
+ if size.length is 2
15
+ page.paperSize = { width: size[0], height: size[1], border: '0px' }
16
+ else
17
+ page.paperSize = { format: system.args[3], orientation: 'portrait', border: '1cm' }
18
+ page.open address, (status) ->
19
+ if status isnt 'success'
20
+ console.log 'Unable to load the address!'
21
+ phantom.exit()
22
+ else
23
+ window.setTimeout (-> page.render output; phantom.exit()), 200
@@ -0,0 +1,28 @@
1
+ var page = require('webpage').create(),
2
+ system = require('system'),
3
+ address, output, size;
4
+
5
+ if (system.args.length < 3 || system.args.length > 4) {
6
+ console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
7
+ console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
8
+ phantom.exit();
9
+ } else {
10
+ address = system.args[1];
11
+ output = system.args[2];
12
+ page.viewportSize = { width: 600, height: 600 };
13
+ if (system.args.length === 3 && system.args[1].substr(-4) === ".pdf") {
14
+ size = system.args[2].split('*');
15
+ page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
16
+ : { format: system.args[2], orientation: 'portrait', margin: '1cm' };
17
+ }
18
+ page.open(address, function (status) {
19
+ if (status !== 'success') {
20
+ console.log('Unable to load the address!');
21
+ } else {
22
+ window.setTimeout(function () {
23
+ page.render(output);
24
+ phantom.exit();
25
+ }, 200);
26
+ }
27
+ });
28
+ }
@@ -0,0 +1,50 @@
1
+ # Render Multiple URLs to file
2
+ # FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
3
+
4
+ system = require 'system'
5
+
6
+ # Extend the Array Prototype with a 'foreach'
7
+ Array.prototype.forEach = (action) ->
8
+ for i, j in this
9
+ action j, i, _len
10
+
11
+ # Render a given url to a given file
12
+ # @param url URL to render
13
+ # @param file File to render to
14
+ # @param callback Callback function
15
+ renderUrlToFile = (url, file, callback) ->
16
+ page = require('webpage').create()
17
+ page.viewportSize = { width: 800, height : 600 }
18
+ page.settings.userAgent = 'Phantom.js bot'
19
+
20
+ page.open url, (status) ->
21
+ if status isnt 'success'
22
+ console.log "Unable to render '#{url}'"
23
+ else
24
+ page.render file
25
+
26
+ delete page
27
+ callback url, file
28
+
29
+ # Read the passed args
30
+ if system.args.length > 1
31
+ arrayOfUrls = Array.prototype.slice.call system.args, 1
32
+ else
33
+ # Default (no args passed)
34
+ console.log 'Usage: phantomjs render_multi_url.coffee [domain.name1, domain.name2, ...]'
35
+ arrayOfUrls = [
36
+ 'www.google.com',
37
+ 'www.bbc.co.uk',
38
+ 'www.phantomjs.org'
39
+ ]
40
+
41
+ # For each URL
42
+ arrayOfUrls.forEach (pos, url, total) ->
43
+ file_name = "./#{url}.png"
44
+
45
+ # Render to a file
46
+ renderUrlToFile "http://#{url}", file_name, (url, file) ->
47
+ console.log "Rendered '#{url}' at '#{file}'"
48
+ if pos is total - 1
49
+ # Close Phantom if it's the last URL
50
+ phantom.exit()
@@ -0,0 +1,62 @@
1
+ // Render Multiple URLs to file
2
+ // FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
3
+
4
+ var system = require('system');
5
+
6
+ // Extend the Array Prototype with a 'foreach'
7
+ Array.prototype.forEach = function (action) {
8
+ var i, len;
9
+ for ( i = 0, len = this.length; i < len; ++i ) {
10
+ action(i, this[i], len);
11
+ }
12
+ };
13
+
14
+ /**
15
+ * Render a given url to a given file
16
+ * @param url URL to render
17
+ * @param file File to render to
18
+ * @param callback Callback function
19
+ */
20
+ function renderUrlToFile(url, file, callback) {
21
+ var page = require('webpage').create();
22
+ page.viewportSize = { width: 800, height : 600 };
23
+ page.settings.userAgent = "Phantom.js bot";
24
+
25
+ page.open(url, function(status){
26
+ if ( status !== "success") {
27
+ console.log("Unable to render '"+url+"'");
28
+ } else {
29
+ page.render(file);
30
+ }
31
+ delete page;
32
+ callback(url, file);
33
+ });
34
+ }
35
+
36
+ // Read the passed args
37
+ var arrayOfUrls;
38
+ if ( system.args.length > 1 ) {
39
+ arrayOfUrls = Array.prototype.slice.call(system.args, 1);
40
+ } else {
41
+ // Default (no args passed)
42
+ console.log("Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]");
43
+ arrayOfUrls = [
44
+ 'www.google.com',
45
+ 'www.bbc.co.uk',
46
+ 'www.phantomjs.org'
47
+ ];
48
+ }
49
+
50
+ // For each URL
51
+ arrayOfUrls.forEach(function(pos, url, total){
52
+ var file_name = "./" + url + ".png";
53
+
54
+ // Render to a file
55
+ renderUrlToFile("http://"+url, file_name, function(url, file){
56
+ console.log("Rendered '"+url+"' at '"+file+"'");
57
+ if ( pos === total-1 ) {
58
+ // Close Phantom if it's the last URL
59
+ phantom.exit();
60
+ }
61
+ });
62
+ });
@@ -0,0 +1,61 @@
1
+ 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
+ ##
15
+ waitFor = (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
+
34
+ if system.args.length isnt 2
35
+ console.log 'Usage: run-jasmine.coffee URL'
36
+ phantom.exit()
37
+
38
+ page = require('webpage').create()
39
+
40
+ # Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
41
+ page.onConsoleMessage = (msg) ->
42
+ console.log msg
43
+
44
+ page.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()
@@ -0,0 +1,79 @@
1
+ var 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
+ */
15
+ function waitFor(testFx, onReady, timeOutMillis) {
16
+ var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timeout 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 100ms
36
+ };
37
+
38
+
39
+ if (system.args.length !== 2) {
40
+ console.log('Usage: run-jasmine.js URL');
41
+ phantom.exit();
42
+ }
43
+
44
+ var page = require('webpage').create();
45
+
46
+ // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
47
+ page.onConsoleMessage = function(msg) {
48
+ console.log(msg);
49
+ };
50
+
51
+ page.open(system.args[1], function(status){
52
+ if (status !== "success") {
53
+ console.log("Unable to access network");
54
+ phantom.exit();
55
+ } else {
56
+ waitFor(function(){
57
+ return page.evaluate(function(){
58
+ if (document.body.querySelector('.runner .description')) {
59
+ return true;
60
+ }
61
+ return false;
62
+ });
63
+ }, function(){
64
+ page.evaluate(function(){
65
+ console.log(document.body.querySelector('.description').innerText);
66
+ list = document.body.querySelectorAll('div.jasmine_reporter > div.suite.failed');
67
+ for (i = 0; i < list.length; ++i) {
68
+ el = list[i];
69
+ desc = el.querySelectorAll('.description');
70
+ console.log('');
71
+ for (j = 0; j < desc.length; ++j) {
72
+ console.log(desc[j].innerText);
73
+ }
74
+ }
75
+ });
76
+ phantom.exit();
77
+ });
78
+ }
79
+ });
@@ -0,0 +1,64 @@
1
+ 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
+ ##
15
+ waitFor = (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
+
34
+ if system.args.length isnt 2
35
+ console.log 'Usage: run-qunit.coffee URL'
36
+ phantom.exit(1)
37
+
38
+ page = require('webpage').create()
39
+
40
+ # Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
41
+ page.onConsoleMessage = (msg) ->
42
+ console.log msg
43
+
44
+ page.open system.args[1], (status) ->
45
+ if status isnt 'success'
46
+ console.log 'Unable to access network'
47
+ phantom.exit(1)
48
+ else
49
+ waitFor ->
50
+ page.evaluate ->
51
+ el = document.getElementById 'qunit-testresult'
52
+ if el and el.innerText.match 'completed'
53
+ return true
54
+ return false
55
+ , ->
56
+ failedNum = page.evaluate ->
57
+ el = document.getElementById 'qunit-testresult'
58
+ console.log el.innerText
59
+ try
60
+ return el.getElementsByClassName('failed')[0].innerHTML
61
+ catch e
62
+ return 10000
63
+
64
+ phantom.exit if parseInt(failedNum, 10) > 0 then 1 else 0