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:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With