openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

phantom_driver.js (921B)


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