Phantomjs cannot start

I used AngularJS in my project and karma for testing. Then I set up karma as follows:

config.set({ basePath: '../', frameworks: ['jasmine'], files: [ // bower:js 'bower_components/jquery/dist/jquery.js', 'bower_components/angular/angular.js', 'bower_components/bootstrap/dist/js/bootstrap.js', 'bower_components/angular-animate/angular-animate.js', 'bower_components/angular-cookies/angular-cookies.js', 'bower_components/angular-route/angular-route.js', 'bower_components/angular-sanitize/angular-sanitize.js', 'bower_components/angular-mocks/angular-mocks.js', // endbower 'js/**/*.js', 'test/spec/**/*.js' ], browsers: [ 'PhantomJS' ], plugins: [ 'karma-phantomjs-launcher', 'karma-jasmine' ], port: 8890 }) 

And shake like this:

 grunt.initConfig({ connect: { testserver: { options: { base: 'js/', hostname: 'localhost', port: '8889' } } }, karma: { unit: { configFile: './test/karma-unit.conf.js', singleRun: true } } }); grunt.registerTask('test', ['connect', 'karma:unit']); 

When I type 'grunt test', the console shows that phantomjs cannot start:

 Running "connect:testserver" (connect) task Started connect web server on http://localhost:8889 Running "karma:unit" (karma) task INFO [karma]: Karma v0.12.31 server started at http://localhost:8890/ INFO [launcher]: Starting browser PhantomJS ERROR [launcher]: Cannot start PhantomJS INFO [launcher]: Trying to start PhantomJS again (1/2). ERROR [launcher]: Cannot start PhantomJS INFO [launcher]: Trying to start PhantomJS again (2/2). ERROR [launcher]: Cannot start PhantomJS ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up. Warning: Task "karma:unit" failed. Use --force to continue. Aborted due to warnings. 

How can i solve this? Can anybody help me?

+6
source share
5 answers

I came across this too, it seemed like the problem is that karma-phantomjs2-launcher is looking for the phantomjs executable. It uses PHANTOMJS_BIN to run phantomjs, so I solved it as follows:

 export PHANTOMJS_BIN=/usr/local/bin/phantomjs 

For now, you can also run "phantomjs" from the command line, and this works, perhaps it is possible.

+7
source

Install libfontconfig. Assuming you are on ubuntu:

sudo apt-get install libfontconfig

This resolved it for me.

+5
source

Upgrade karma-phantomjs-launcher to version 1.0.2 in package.json and reinstall the package.

+2
source

Maybe this helps someone. Suddenly I received the same console messages for no good reason, I just stopped and wanted to restart it.

I npm remote karma and reinstalled karma.

0
source

If you installed the Chrome browser on your computer, switch to it.

In the array of browsers, write Chrome instead of PhantomJS, and in the array of plugins use karma-chrome-launcher.
"karma-chrome-launcher is available as another node package, it must be installed.

 browsers: [ 'Chrome' ], plugins: 'karma-chrome-launcher', 'karma-jasmine' ], 
-1
source

Source: https://habr.com/ru/post/983366/


All Articles