3

I'm using PhantomJS 1.8.2 to run some Jasmine unit tests using JsTestDriver. The tests run fine using Chrome, but about half the time when using PhantomJS, the test result is that no test cases were found.

I've narrowed the issue down to PhantomJS failing to open the local JsTestDriver page (http://localhost:9876/capture). Here's how to reproduce this, about 50% of the times, the Loaded ... with status ... message is never shown:

  • Start JsTestDriver server locally
  • Run phantomjs phantomjs-jstd-bridge.js

The file phantomjs-jstd-bridge.js looks like this:

var page = require('webpage').create();
var url = 'http://localhost:9876/capture';
console.log('Loading ' + url);
page.open(url, function(status) {
  console.log('Loaded ' + url + ' with status ' + status);
});

The first log line (Loading ...) is always displayed, but the second line coming from the callback is only printed about half the time.

What could be the cause for this? Opening the URL in question in a web browser works fine every time.

Is there any way to get more info on why PhantomJS does not call the callback?

nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • Since you are using a callback function in your test you might have to use an [AsyncTestCase](https://code.google.com/p/js-test-driver/wiki/AsyncTestCase). – Uooo Mar 18 '13 at 06:57

1 Answers1

1

Check some tips mentioned in the Troubleshooting wiki page. Particularly useful is tracking the network transfer activity as it may indicate whether some resources are not sent properly or other similar problems.

Ariya Hidayat
  • 12,523
  • 3
  • 46
  • 39