How to configure CHROME_BIN path in Jenkins env variable for Headless Chrome

TheParam picture TheParam · Apr 2, 2019 · Viewed 7.2k times · Source

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
  });
};

Answer

Max Nanasy picture Max Nanasy · May 13, 2020

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