Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma with ChromeHeadless on Jenkins CI with Debian

We are moving from PhantomJS to ChromeHeadless in our testing environment with Karma & Jasmine for our frontend Node.js app. Locally, it is just necessary to replace the field

browsers: ['PhantomJS'],

with

browsers: ['ChromeHeadless'],

and add the entry in the package.json:

"karma-chrome-launcher": "x.y.z",

Then the npm build will take the locally installed chrome browser instance to run the Jasmine tests. This works correctly.

On our jenkins build server (which runs on Debian Jessie), there is no chrome installed, so the tests cannot be executed.

Now the question:

  • Is there an NPM package for chrome , which I can install, so that I don't have to install it on the debian machine directly? (Similar to phantomjs-prebuilt, which installs the current PhantomJS instance before running the actual test case)

UPDATE: Yes, there is the NPM package puppeteer, see: https://github.com/GoogleChrome/puppeteer. This will fetch a chrome version depending on the current build machine. Therefore a new entry the package.json file must be added (or installed via npm install puppeteer -D):

"puppeteer": "x.y.z",

and the karma.conf:

process.env.CHROME_BIN = require('puppeteer').executablePath();

browsers: ['HeadlessChrome'],
        customLaunchers: {
            HeadlessChrome: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox']
            }
        },

Be aware that with Debian, there sometimes must be installed missing dependencies. See: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

like image 470
schowave Avatar asked Feb 22 '18 09:02

schowave


1 Answers

There is a better way to do this than bundling chromium everywhere you. You can set environment vars to tell Puppeteer to install or not install Chromium. So locally, go ahead and install the chromium but on the CI server set the env variable to not install chromium.

Then you can get the browserless image and run that for the CI servers chrome. The reason this is much better is due to amount of dependencies you need to install on the server in order to get Chromium to work. Using the Docker image is much better way to do it.

Refer to the documentation here: https://docs.browserless.io/docs/docker-quickstart.html

Refer to the answer in this question! for the karma config on how to do this with the selenium chrome image

like image 70
Nanotron Avatar answered Nov 09 '22 10:11

Nanotron