https://cypress.io logo
Run cypress tests in Gitlab with parallel
# i-need-help
m
I would like to run my tests from Gitlab in the Cypress cloud dashboard in parallel. When I use the command in my gitlab ci file:
Copy code
npx cypress run --record --key <some key> --parallel --headless
I expected that Cypress will run the tests in parallel across multiple machines, when I verify in the dashboard if it ran on multiple machines, it just states that it ran on 1 machine, and the speed could be improvement by adding more machines. For this PoC it just has 4 tests. Apparently I am doing something wrong, but I am not entirely sure what. - What am I missing? - How I can distribute the tests over multiple machines to speed up the execution? Because there are multiple runners available in our Gitlab instance. Thanks in advance! Gitlab file
Copy code
variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - cache/Cypress
    - node_modules

build_cypress:
  image: <cypress image in container registry>
  <<: *cypress_rules
  stage: prepare
  script:
    - cd legacy/e2e
    - npm ci
    - npx cypress cache path
    - npx cypress cache list

run_cypress_folder_1:
  image: <cypress image in container registry>
  <<: *cypress_rules
  stage: test
  parallel: 5
  script:
    - cd legacy/e2e
    - npm install cypress
    - npx cypress run --record --key <SOMEKEY> --parallel --headless
  artifacts:
    when: always
    paths:
      # the path here is needed to expose the file and be able to send it to Datadog.
      - $CI_PROJECT_DIR/legacy/e2e/cypress/results/**/*.xml
https://docs.cypress.io/guides/guides/parallelization https://docs.cypress.io/guides/continuous-integration/gitlab-ci
e
Might be a dumb question but you stated that your PoC only has 4 tests. Can you confirm that means across 4 specs? Or is this just one spec file?
Cypress' parallelization strategy is file-based, so in order to utilize parallelization, your tests will need to be split across separate files.
m
hi @enough-truck-68085 ! 4 different js files, for the PoC. Spec1, 2,3 and 4 etc. Let me know if you would need more info, from my side 🙂 thanks!
g
I don't know about cloud, but my cypress-split plugin has gitlab ci example that runs in parallel https://github.com/bahmutov/cypress-split#gitlab-ci
m
Thanks for the prompt response @gray-kilobyte-89541 much appreciated! I will check this out right away 🙂
This works like a charm @gray-kilobyte-89541!
g
🙂 nice
3 Views