1

i have a sproutcore app, whose tests i want to execute from an ant script. the site interacts with a rails application so that when /backend occurs in the url, the request goes to a rails server. now when i enter 'sc-server' on the command line, i can visit the tests tab. if rails server is not running, it complains that the rails application is not running, so i have to do 'rails server' from the rails application, and then i can run the sproutcore application tests by opening various urls in the browser, example http://localhost:4020/sproutcore/tests#myapp&test=unit/login_controller

my question is: how can i execute the tests without using the browser? what are the commands i can use to run these tests and get output on the command line?

1 Answer 1

0

install https://github.com/ariya/phantomjsphantomjs then you can run the following script after starting both the sproutcre app and the rails app

var allTestsURL = "http://localhost:4020/webedge/en/current/tests.html";
var i, j;
var x = 0, y = 0;
var page = new WebPage();

page.open(allTestsURL, function (status) {
  if (status !== 'success') {
    console.log('Unable to access network');
  }
  window.setInterval(function() {
  var str = "";
  y++;
  var st = page.evaluate(function () {
    str = "";
    if(document.body.querySelector("span.status span.passed")){
      str += "passed: true";
      console.log("str: " + str);
    }
    if (document.body.querySelector("span.status span.failed")){
      str += ";failed: true";
      console.log("str: " + str);
    }
    console.log("returning " + str);
    return str;
  });
    console.log("status returned is " + st);
    if (st == "passed: true") {
      console.log("it all passes! ");
      phantom.exit(0);
    } else if(st.indexOf("failed") > 0){
      console.log("tests have failed");
      phantom.exit(1);
    }
    if(y > 25) {
      console.log("exiting with error as not yet resolved");
      phantom.exit(1);

    }
    }, 2000);
});

Note: sproutcore version is 1.6.0.1, and the passed tests appear in the span.passed selector, and the failed tests if any occure in the span.failed selector. i havent counted the failed tests; this script just detects if there are failures or not. it is not completely foolproof but it serves my purpose. there is no timeout or anything, may be that should be added. but we can build on it.

the script at sproutcore phantomjs was explored, but it did not work for me. any ideas why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.