Karma - Chrome failed 2 times (cannot start). Giving up

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I've been trying to run my tests using karma-chrome-launcher, but everytime I run my tests it throws this error:

INFO [launcher]: Starting browser Chrome ERROR [launcher]: Cannot start 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's 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'm installing the module here: https://www.npmjs.com/package/karma-chrome-launcher

Thanks!

回答1:

I had the same problem and tried a lot of the suggested solutions I found, but what finally solved it for me was to delete the node_modules folder and getting everything new via npm install



回答2:

I got my inspiration partially from here: https://stackoverflow.com/a/33802985/1534823

Also use logLevel: config.LOG_DEBUG - it can help you get good information on what is causing your error`

Check following settings in karma.conf:

captureTimeout: 60000, browserNoActivityTimeout: 360000 browser: ["Firefox"] 
  • captureTimeout - your browser may take some time to start. LOG_DEBUG should show some error related to capturing your browser
  • browserNoActivityTimeout - PhantomJS is really slow(x10) on my machine, in comparison to Firefox and Chrome. Karma may timeout before your tests complete.
  • browser - our jenkins server runs on linux, where we had no 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 you described above.



回答3:

Had the same issue with my build environment.

What i did is to follow the advice of Rafael Cichocki to enable the debugging:

logLevel: config.LOG_DEBUG 

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

Turned out that chrome browser was crashing due to missing ttf fonts. So running:

apt-get install ttf-freefont 

Solved that issue for me and karma started to launch chrome.



回答4:

I noticed when I had this error that when I changed the spec file and saved it, it seemed to work again. I had a few errors in typescript that didn't break the tests (passing in null arguments to a virtual component instance constructor). I don't know if it was resolving the errors since they existed before when it was working, or if changing the file and saving it updated the cache.

So this could mean that clearing the cache in Chrome could also potentially resolve it. It's working now again for me so I can't check to verify.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!