9

We've set up a Jenkins CI server running Karma targeting PhantomJS. We're running our tests through Grunt. Jenkins, Grunt, and Phantom are all running correctly, and Karma seems to start up fine, but Karma can't capture Phantom. Our scripts run locally (OSX) just fine. The same error exists running via bash or through Jenkins:

Running "karma:jenkins-unit" (karma) task
[2013-07-03 11:03:12.168] [WARN] config - urlRoot normalized to "/__karma/"
DEBUG [reporter]: Using reporter "dots".
DEBUG [reporter]: Using reporter "junit".
DEBUG [reporter]: Using reporter "coverage".
INFO [karma]: Karma server started at http://localhost:8084/__karma/
INFO [launcher]: Starting browser PhantomJS
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
INFO [karma]: To run via this server, use "karma run --runner-port 9104"
...
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
INFO [launcher]: Trying to start PhantomJS again.
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
INFO [launcher]: Trying to start PhantomJS again.
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [karma]: PhantomJS failed to capture, aborting the run.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: Killing PhantomJS
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
Warning: Task "karma:jenkins-unit" failed. Use --force to continue.

Our server is CentOS 6.4.

Here are the versions we have running: grunt-cli v0.1.9 grunt v0.4.1 node 0.10.12 and 0.8.25. phantomjs 1.9.1 karma 0.8.6

Any help would be much appreciated!

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
sak_to
  • 399
  • 4
  • 13
  • I have a totally different setup from you, but when I got the `PhantomJS failed to capture` error, it turned out to be that localhost didn't map to 127.0.0.1. That's something that can trigger this error. – mcv Apr 14 '14 at 08:42

2 Answers2

6

Use polling instead of sockets and absolute paths instead of relative paths in the karma.conf.js configuration file to ensure the directory structure is being traversed correctly and the client/server connection has no external dependencies:

module.exports = function(config) 
  {
  var absolute_root = process.cwd() + '/';
  config.set
  (
    {
    // https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // list of files

    files: 
       [
       absolute_root + 'test/Spec/**/*.js',
       absolute_root + 'js/*.js',
       absolute_root + '../libs/jquery.js'
       ],

     usePolling: true,

     transports: ['xhr-polling', 'jsonp-polling'],

     browsers: ['PhantomJS']
    }
  );
  };

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
0

In my case adding

transports: ['xhr-polling', 'jsonp-polling']

to karma.conf.js was sufficient. The real problem was a very old version of karma (0.12). Now with 1.4. I don't need CPU consuming polling.

Porteano
  • 21
  • 4