1
0

phantom_driver.js 921 B

12345678910111213141516171819202122232425262728293031
  1. var page = require('webpage').create();
  2. page.open("http://localhost:3000/test/index.html", function (status) {
  3. if (status != "success") {
  4. console.log("page couldn't be loaded successfully");
  5. phantom.exit(1);
  6. }
  7. waitFor(function () {
  8. return page.evaluate(function () {
  9. var output = document.getElementById('status');
  10. if (!output) { return false; }
  11. return (/^(\d+ failures?|all passed)/i).test(output.innerText);
  12. });
  13. }, function () {
  14. var failed = page.evaluate(function () { return window.failed; });
  15. var output = page.evaluate(function () {
  16. return document.getElementById('output').innerText + "\n" +
  17. document.getElementById('status').innerText;
  18. });
  19. console.log(output);
  20. phantom.exit(failed > 0 ? 1 : 0);
  21. });
  22. });
  23. function waitFor (test, cb) {
  24. if (test()) {
  25. cb();
  26. } else {
  27. setTimeout(function () { waitFor(test, cb); }, 250);
  28. }
  29. }