Karma - Chrome failed 2 times (cannot start). Giving up
Solution 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
.
Solution 2
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.
Solution 3
browsers: ['PhantomJS']
, Here allowed browser is PhantomJs
, but code is trying for Chrome, which is not a specified browser in the karma.conf.js.
Change karma.conf.js
file :
browsers: ['PhantomJS','Chrome', 'ChromeHeadless']
,
chrome- is for opening new chrome browser window.
ChromeHeadless- is for running tests without opening browser window
make sure Chrome is installed and added to PATH
Hope this helps
Solution 4
In Karma.conf.js
, Increase timeouts to 60000
captureTimeout: 60000,
browserDisconnectTimeout: 60000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
Solution 5
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.
SupimpaAllTheWay
Updated on July 17, 2022Comments
-
SupimpaAllTheWay almost 2 years
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!
-
danday74 about 6 yearsgenious, turn it off and on again, works every time!
-
Kieran Ryan over 5 yearsNot working for me :-( Since Friday Chrome server generally not connecting. Before that less problems.. don't ask me what's changed..
-
Sree about 2 yearsThis doesnt help me either.