Cypress tests are green locally, but failing in Gitlab CI

Viewed 2221

I implemented e2e tests with Cypress. They work fine and I can run them with command line based on the packaged version of the application: npm run ci:cy-run.

Here are the commands from package.json:

"ci:start-server": "angular-http-server --path ./dist/treo -p 4200",
"cy:run": "cypress run --project e2e --browser chrome --headless",
"ci:cy-run": "start-server-and-test ci:start-server http://localhost:4200 cy:run"

When I try to execute this command in Gitlab CI with this .gitlab-ci.yml file:

image: teracy/angular-cli:latest
image: cypress/browsers:node12.16.2-chrome81-ff75
build:
    stage: build
    cache:
        paths:
            - node_modules/
    script:
        - npm install --quiet
        - npm run build:prod
    artifacts:
        paths:
            - dist/myapp
test:
    stage: test
    cache:
        policy: pull
    paths:
        - node_modules/
  script:
      - npm run lint
      - npx cypress install
      - npm run ci:cy-run

I got some errors like:

 CypressError: Timed out retrying: `cy.type()` failed because this element is not visible:
`<input formcontrolname="verificationCode" name="verificationCode" matinput="" placeholder="Code à 6 chiffres" required="" type="string" minlength="6" maxlength="6" class="mat-input-element mat-form-field-autofill-control ng-tns-c27-2 ng-untouched ng-pristine ng-invalid cdk-text-field-autofill-monitored" id="mat-input-0" aria-invalid="false" aria-required="true">`
This element `<input#mat-input-0.mat-input-element.mat-form-field-autofill-control.ng-tns-c27-2.ng-untouched.ng-pristine.ng-invalid.cdk-text-field-autofill-monitored>` is not visible because its parent `<div.mat-form-field-infix.ng-tns-c27-2>` has CSS property: `visibility: hidden`
Fix this problem, or use `{force: true}` to disable error checking.

https://on.cypress.io/element-cannot-be-interacted-with

Is there some specific configuration to do for Gitlab? How to debug this problem since I can't get generated files (images, videos) from CI?

Thanks very much for your help! Thierry

1 Answers

You can get videos/screenshots from Cypress in gitlab CI using artifacts, just make sure they are put inside the app's folder structure.

Example I'm working on right now which yields a downloadable screenshots folder:

e2e tests all:
  image: cypress/base:14.15.4
  stage: manual-tests
  when: manual
  allow_failure: true
  before_script:
    - npm install
    - npx cypress verify
  script:
    - npm run-script test:e2e
  cache:
    <<: *global_cache
    policy: pull
  artifacts:
    paths:
      - tests/e2e/screenshots/**/*.png
    expire_in: 2 hrs
    when: on_failure

This gets the screenshots folder in our VueJS app.

Cypress CI artifact examples here and general Gitlab artifacts info here.

Related