12

I'm working on basic Angular project and I'm able to run the test with karma and Jasmin on my Windows with headless chrome. But Jenkins says that No binary for ChromeHeadless browser on your platform, so the question is how to configure the ChromeHeadless in Jenkins configuration.

Error log

No binary for ChromeHeadless browser on your platform. Please, set CHROME_BIN" env variable. npm ERR! Test failed.

package.json

 "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~6.0.8",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "^2.9.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage": "^1.1.2",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-sonarqube-unit-reporter": "0.0.18",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "^2.9.2"
  }

karma.conf.js

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {

  config.set({
    basePath: '',
    // captureTimeout: 60000, // it was already there
    // browserDisconnectTimeout: 10000,
    // browserDisconnectTolerance: 1,
    // browserNoActivityTimeout: 60000, //by default 10000
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-coverage'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      // require('@angular/cli/plugins/karma'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-sonarqube-unit-reporter'),
      // require('karma-phantomjs-launcher')

    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      // dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      useBrowserName: false,
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml', 'sonarqubeUnit', 'coverage'],
    sonarQubeUnitReporter: {
      outputFile: '../../target/angular_reports/ut_report.xml',
      useBrowserName: false
    },
    // angularCli: {
    //   environment: 'dev'
    // },
    coverageReporter: {
      // specify a common output directory
      dir: '../../target/angular_reports/coverage',
      reporters: [
        // reporters not supporting the `file` property
        {
          type: 'html',
          subdir: 'report-html'
        },
        {
          type: 'lcov',
          subdir: 'report-lcov'
        },
        // reporters supporting the `file` property, use `subdir` to directly
        // output them in the `dir` directory
        {
          type: 'cobertura',
          subdir: '.',
          file: 'cobertura.txt'
        },
        {
          type: 'lcovonly',
          subdir: '.',
          file: 'report-lcovonly.txt'
        },
        {
          type: 'teamcity',
          subdir: '.',
          file: 'teamcity.txt'
        },
        {
          type: 'text',
          subdir: '.',
          file: 'text.txt'
        },
        {
          type: 'text-summary',
          subdir: '.',
          file: 'text-summary.txt'
        },
      ]
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    // browsers: ['Chrome'],
    // browsers: ['ChromeHeadless'],
    // browsers: ['Chrome'],
    browsers: ['MyHeadlessChrome'],
    // browsers: ['Chrome', 'ChromeHeadless', 'MyHeadlessChrome'],
    customLaunchers: {
      MyHeadlessChrome: {
        base: 'ChromeHeadless',
        flags: ['--disable-translate', '--disable-extensions', '--remote-debugging-port=9223']
      }
    },
    // singleRun: false
    singleRun: true
  });
};
Cœur
  • 37,241
  • 25
  • 195
  • 267
TheParam
  • 10,113
  • 4
  • 40
  • 51
  • 1
    check this question: https://stackoverflow.com/questions/45881228/how-to-add-the-chrome-binary-to-run-e-g-karma-tests-on-headless-chrome-on-a-ci – jahller Apr 02 '19 at 08:25
  • 1
    Possible duplicate of [How to add the chrome binary to run e.g. Karma tests on headless chrome on a CI server](https://stackoverflow.com/questions/45881228/how-to-add-the-chrome-binary-to-run-e-g-karma-tests-on-headless-chrome-on-a-ci) – jahller Apr 02 '19 at 08:26
  • 1
    I have checked that solution it's not working anymore have you tried buddy @jahller – TheParam Apr 02 '19 at 08:43

1 Answers1

-5

You could set the CHROME_BIN environment variable to the location of a chrome browser executable

Max Nanasy
  • 5,871
  • 7
  • 33
  • 38