cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.86k stars 3.17k forks source link

CircleCI - error while loading shared libraries #2999

Closed udos closed 5 years ago

udos commented 5 years ago

when I try to run cypress tests in CircleCI via npm run cy:run, the following error is thrown:

npm run cy:run

> trail-scout@1.0.0 cy:run /home/circleci/project
> cypress run

It looks like this is your first time using Cypress: 3.1.3

[12:33:54]  Verifying Cypress can run /home/circleci/.cache/Cypress/3.1.3/Cypress [started]
[12:33:54]  Verifying Cypress can run /home/circleci/.cache/Cypress/3.1.3/Cypress [failed]
Cypress failed to start.

This is usually caused by a missing library or dependency.

The error below should indicate which dependency is missing.

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.
----------

/home/circleci/.cache/Cypress/3.1.3/Cypress/Cypress: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory
----------

Platform: linux (Debian - 9.5)
Cypress Version: 3.1.3

as a workaround I install the missing dependencies manually (before I run cypress tests):

sudo apt-get update
sudo apt-get install libxtst6 libgconf-2-4 libnss3 libasound2
YOU54F commented 5 years ago

Cypress provide docker images for circle with all deps

https://github.com/cypress-io/cypress-example-docker-circle/blob/master/circle.yml

udos commented 5 years ago

@YOU54F, I tried that before. same error.

bahmutov commented 5 years ago

@udos please provide your full circleci file. We run literally hundreds of projects on Circle, and we recommend using Cypress docker images https://github.com/cypress-io/cypress-docker-images as a base, because they have all OS dependencies installed already.

The simplest way to run Cypress on Circle is via Cypress orb, see here: https://github.com/cypress-io/circleci-orb

udos commented 5 years ago

@bahmutov, I tried orbs after I got "inspired" :) by your presentation https://www.youtube.com/watch?v=J-xbNtKgXfY (but I got stuck and switched to the old school way of doing it).

my .circleci/config.yml to get cypress doing something on circleci is this

version: 2.1

orbs:
  # source: https://circleci.com/orbs/registry/orb/cypress-io/cypress
  cypress: cypress-io/cypress@1.3.0

jobs:
  build-demo:
    docker:
      - image: circleci/python:3.6.6-stretch-node
        environment:
          DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
          DJANGO_SETTINGS_MODULE: trails_dj.settings
          DJANGO_DEBUG: 1
          DJANGO_ENABLE_SSL: 0
      - image: circleci/postgres:9.6.5-alpine-ram
        environment:
          POSTGRES_USER: root
          POSTGRES_DB: circle_test
          POSTGRES_PASSWORD: ""
      - image: cypress/base:8
        environment:
          # this enables colors in the output
          TERM: xterm
    steps:
      - checkout
      - restore_cache:
          key: deps-py-{{ .Branch }}-{{ checksum "requirements/all.txt" }}
      - restore_cache:
          key: deps-npm-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run:
          name: install python and npm dependencies
          command: |
            python3 -m venv venv
            echo 'activate virtual environment'
            . venv/bin/activate
            echo 'install pip requirements'
            pip install -r requirements/all.txt
            echo 'install npm dependencies'
            npm install
            echo 'bundle webpack dev'
            npm run build:dev
      - save_cache:
          key: deps-py-{{ .Branch }}-{{ checksum "requirements/all.txt" }}
          paths:
            - "venv"
            - "/usr/local/bin"
            - "/usr/local/lib/python3.6/site-packages"
      - save_cache:
          key: deps-npm-{{ .Branch }}-{{ checksum "package-lock.json" }}
          paths:
            - "node_modules"
            - ".cache/Cypress"
      - run:
          name: run unit tests with coverage report
          command: |
            . venv/bin/activate
            coverage run ./manage.py test accounts file maps route segment strava trails_dj
            coverage report -m
            coverage xml
      - run:
          name: run django migrations
          command: |
            . venv/bin/activate
            python manage.py migrate
      - run:
          name: run django server in background
          command: |
            . venv/bin/activate
            python manage.py runserver localhost:8000
          background: true
      - restore_cache:
          key: deps-py-{{ .Branch }}-{{ checksum "requirements/all.txt" }}
      - restore_cache:
          key: deps-npm-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run:
          name: run cypress tests
          command: |
            . venv/bin/activate
            sleep 5
            curl --retry-delay 5 --retry 15 --retry-connrefused http://localhost:8000
            npm run cy:run
      - store_test_results:
          path: multiple-results
      - store_artifacts:
          path: cypress/videos
      - store_artifacts:
          path: cypress/screenshots
workflows:
  version: 2
  build-deploy:
    jobs:
      - build-demo:
          filters:
            branches:
              only: circleci
bahmutov commented 5 years ago

@udos so it seems to me Cypress tests run in image circleci/python:3.6.6-stretch-node right? which does not have Cypress OS dependencies ...

udos commented 5 years ago

@bahmutov yes. I need python to start django server to run cypress tests.

bahmutov commented 5 years ago

@udos I am afraid there is no getting around it then - you need the Cypress OS dependencies http://on.cypress.io/continuous-integration#Dependencies in the image that actually runs Cypress tests. Maybe there is a way in Circle to run your server in one image (the image with Python), and run Cypress tests in another image (cypress/base:8 in your case), but I don't know how one would configure this

udos commented 5 years ago

@bahmutov, no worries. I was about to propose you what you wrote ;) note: maybe as a CircleCI partner they could add this dependendencies to images they provide (to make cypress integration easier).

last (related) question: in this case orbs don't help either. they simplify things only for node.js based projects. correct?

bahmutov commented 5 years ago

Yes, we will propose adding these dependencies to Circle full images

And yes, orbs are not going to help with cases when you need different environments in Circle, or at least I don't know if they can help here

udos commented 5 years ago

thanks. no worries. cypress is a great tool!

piotrekno1 commented 4 years ago

@bahmutov it seems Cypress prepared images for python/ruby/XXX + headless browser based testing. I am able to run cypress based e2e tests with circleci/{lang}:{version}-node-browsers type of an image.

Example: circleci/python:3.8-node-browsers

bahmutov commented 4 years ago

Excellent but these are circleci prepared images not by cypress

Sent from my iPhone

On Nov 17, 2019, at 15:32, Piotr Duda notifications@github.com wrote:

 @bahmutov it seems Cypress prepared images for python/ruby/XXX + headless browser based testing. I am able to run cypress based e2e tests with circleci/{lang}:{version}-node-browsers type of an image.

Example: circleci/python:3.8-node-browsers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tillias commented 3 years ago

Hello folks, sorry for hijacking this ticket, but is there any documentation available in 2020, about which docker image should I import (I'm not using orbs because of internal reasons) in order to run tests?

Use-case: git clone repo, npm install, then cypress run. I have tried various combinations and installing some ubuntu video dependencies, but there all stuck to

Cypress failed to start.

This is usually caused by a missing library or dependency.

The error below should indicate which dependency is missing.

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.

----------

/home/circleci/.cache/Cypress/5.5.0/Cypress/Cypress: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory

Any help will be really appreciated!

gimpiron commented 3 years ago

hey @tillias have you try this one? https://docs.cypress.io/guides/guides/continuous-integration.html#Docker

bahmutov commented 3 years ago

@tillias you can always inspect our base Docker images to see what Linux libraries we install to have Cypress working https://github.com/cypress-io/cypress-docker-images/tree/master/base

tillias commented 3 years ago

Hello folks, many thanks for the response,

I'm using cypress/browsers:node12.14.1-chrome83-ff77 since November 2020, not sure if it latest, but it simply works:

https://github.com/tillias/microservice-catalog/blob/master/.circleci/config.yml

bahmutov commented 3 years ago

You can find the list of Docker images with pre-installed browsers in our repo https://github.com/cypress-io/cypress-docker-images/tree/master/browsers#cypressbrowsers