Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

integrate puppeteer in gitlab with gitlab-ci.yml

Im currently working on e2e test in Chrome Puppeteer. I am at the stage where it would be ideal to integrate my tests in the development process.

What I want to accomplish is the following: my tests run automated before every deploy to production. If they succeed deployment goes through, if they fail deployment is canceled.

I use a pipeline on gitlab to automate my deployment process. So my main question is how can I integrate my puppeteer tests into the gitlab-ci.yml file?

like image 750
Kristof Vandenbroeck Avatar asked Feb 06 '18 08:02

Kristof Vandenbroeck


3 Answers

This might be a bit of a hack but mine are running like this:

test:
image: node:latest
stage: run
script:
- apt-get update
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- yarn
- yarn test

That super long list of libraries are the ones that the puppeteer needs to launch chrome. Ideally you would have a ready docker image but all the premade ones I found did not work for me.

When getting ready for prod you should build your own image that takes from node and installs the dependencies itself.

like image 169
Rince Avatar answered Oct 20 '22 09:10

Rince


We had the same problem, you need to run the stage on an docker image that provides puppeteer:

# run performance monitor
performanceMonitoring:
  stage: performanceMonitoring
  image: alekzonder/puppeteer
  script:
    - yarn run performanceMonitoring
like image 25
Andreas Köberle Avatar answered Oct 20 '22 09:10

Andreas Köberle


The easiest way to accomplish this is by using a docker image with Puppeteer preinstalled.

This is what your .gitlab-ci.yml` should look like:

stages:
  - test

cache:
  paths:
    - node_modules/

.node_template:
  image: buildkite/puppeteer

tests:
  extends: .node_template
  stage: test
  variables:
    CI: "true"
  before_script:
    - echo "checking node version"
    - node -v
    - echo "installing dependencies..."
    - npm install
  script:
    - npm run test

I recommend using buildkite/puppeteer over alekzonder/puppeteer, since it comes with the latest LTS version of node and alekzonder/puppeteer doesn't.

like image 42
base34 Avatar answered Oct 20 '22 07:10

base34