Karma - Chrome failed 2 times (does not start). Give up

I tried to run my tests using karma-chrome-launcher, but every time I run my tests, it throws this error:

INFO [launcher]: launching the Chrome browser ERROR [launcher]: unable to launch Chrome

INFO [launcher]: Trying to start Chrome again (1/2). ERROR [launcher]: Cannot start Chrome INFO [launcher]: Trying to start Chrome again (2/2). ERROR [launcher]: Cannot start Chrome ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up. 

Here is my karma.conf.js code:

 // Karma configuration // Generated on Mon Mar 23 2015 14:04:19 GMT-0300 (BRT) module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: 'www', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine'], // list of files / patterns to load in the browser files: [ 'lib/ionic/js/angular/angular.js', 'lib/ionic/js/angular/angular-animate.js', 'lib/ionic/js/angular/angular-sanitize.js', '../node_modules/jasmine-core/lib/jasmine-core/jasmine.js', '../node_modules/mock-local-storage/lib/mock-localstorage.js', '../node_modules/angular-mocks/angular-mocks.js', //'../node_modules/requirejs/require.js', 'lib/ionic/js/angular/angular-resource.js', 'lib/ionic/js/angular-ui/angular-ui-router.js', 'lib/ionic/js/ionic.js', 'lib/ionic/js/ionic-angular.js', /*'../tests/libs/ngCordovaMocks.min.js',*/ 'js/lib/ng-cordova.min.js', 'js/*.js', 'js/controllers/*.js', 'js/services/*.js', 'js/factory/*.js', //'../tests/*.js', '../tests/**/*.js' ], // list of files to exclude exclude: [ ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress', 'html'], htmlReporter: { outputFile: '../tests/report/index.html' }, // web server port port: 9876, plugins : [ 'karma-junit-reporter', 'karma-jasmine', 'karma-phantomjs-launcher', 'karma-chrome-launcher' //'karma-htmlfile-reporter' ], // enable / disable colors in the output (reporters and logs) colors: true, // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_INFO, // enable / disable watching file and executing tests whenever any file changes autoWatch: true, // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['PhantomJS'], // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: false }); }; 

I install the module here: https://www.npmjs.com/package/karma-chrome-launcher

Thanks!

+20
source share
7 answers

I had the same problem and I tried many suggested solutions that I found, but the final solution for me was to delete the node_modules folder and get everything new via npm install

+11
source

Had the same problem with my build environment.

What I did was follow the advice of Raphael Chihoki to enable debugging:

 logLevel: config.LOG_DEBUG 

Then he tried to launch the chrome browser with exactly the same line that was visible in its debug output.

It turned out that the chrome browser crashed due to the lack of ttf fonts. So:

 apt-get install ttf-freefont 

I decided that for me and karma the problem of launching chrome began.

+3
source

I noticed that when I had this error, when I changed the specification file and saved it, it seemed to work again. I had a few typescript errors that didn't break the tests (passing null arguments to the constructor of the virtual component instance). I do not know if they resolved errors, since they existed before when they worked, or if I changed the file and saved it, I updated the cache.

Thus, this may mean that clearing the cache in Chrome could also potentially solve the problem. Now it works again for me, so I can not check it.

+2
source

The solution for us with angular cli was to set the following properties in karma.conf.js

  autoWatch: false, singleRun: true 
+1
source

I got my inspiration in part: fooobar.com/questions/160918 / ...

Also use logLevel: config.LOG_DEBUG - it can help you get good information about what causes your error.

Check the following settings in the karma.conf file:

 captureTimeout: 60000, browserNoActivityTimeout: 360000 browser: ["Firefox"] 
  • captureTimeout - Your browser may take some time. LOG_DEBUG should show some error related to hijacking your browser.
  • browserNoActivityTimeout - PhantomJS is very slow (x10) on my machine compared to Firefox and Chrome. Karma can drag on until your tests are complete.
  • browser - our jenkins server runs on linux, where we did not have binaries for chrome, so we had to switch to firefox

If any of these three settings were not set correctly, we would get the error described above.

0
source

I was able to solve this problem by removing the absolute path ( src/examplePath ) and changing it to the relative path ( ../../examplePath ).

Example change in specification:

import { myPackage } from 'src/myPath'; (seems to be a problem)

import { myPackage } from '../../../myPath'; (seems to solve this)

Please note that I tried to remove the node modules and install npm, but this did not work. I'm so not sure why this is important.

0
source

Just in case, if you use it behind a corporate proxy. Make sure you include your 0.0.0.0 in the environment variable NO_PROXY.

Otherwise, your test will go through the firewall first, where it most likely will not be able to reach 0.0.0.0. So just to make sure that I include the following in my

 NO_PROXY=127.0.0.1,localhost,0.0.0.0 

Especially if you run your tests in the container environment (for example, in the assembly pipeline), unconfigured environment variables can be a common reason for ng test to work normally on the local computer, but you cannot connect to google-chrome in the container.

0
source

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


All Articles