没有赛普拉斯仪表板的赛普拉斯并行化

时间:2020-05-23 14:29:43

标签: node.js continuous-integration dependencies cypress offline

有没有一种方法可以运行并行的cypress执行程序,而无需访问cypress仪表板?

我正在尝试让cypress并行运行我的测试,但是看来您必须具有Internet连接才能访问cypress仪表板以记录测试。

任何人都知道我该如何解决这个问题,并使测试并行运行,而不必依赖Cypress Dashboard或Circle CI等特定CI工具?

谢谢!

7 个答案:

答案 0 :(得分:3)

您可以尝试此cypress-parallel-specs-locally

答案 1 :(得分:2)

看看这个免费的解决方案https://github.com/agoldis/sorry-cypress 作为一个简单的示例,我仅在docker-compose中使用director服务来使测试并行运行:

version: '3.7'
networks:
  default:
    external:
      name: bridge

services:
  cypress:
    container_name: cypress
    build:
      context: ../
      dockerfile: ./docker/cy.Dockerfile
    links:
      - director
    ports:
      - '5555:5555'
    network_mode: bridge

  cypress2:
    container_name: cypress2
    build:
      context: ../
      dockerfile: ./docker/cy.Dockerfile
    links:
      - director
    ports:
      - '5556:5556'
    network_mode: bridge

  mongo:
    image: mongo:4.0
    network_mode: bridge
    ports:
      - 27017:27017

  director:
    image: agoldis/sorry-cypress-director:latest
    environment:
      MONGODB_URI: "mongodb://mongo:27017"
    network_mode: bridge
    ports:
      - 1234:1234
    depends_on:
      - mongo

答案 2 :(得分:0)

尝试在Buddy CI / CD中添加赛普拉斯动作。这样,您将在每次推送时构建和测试您的应用程序(它们将部署到您想要的任何位置)。我认为Buddy应该为您解决该问题。

enter image description here

答案 3 :(得分:0)

如果使用GitLab,您总是可以通过 .gitlab-ci.yml 文件手动拆分作业,如下所示:

 1-job:
   stage: acceptance-test
   script:
     - npm install
     - npm i -g wait-on
     - wait-on -t 60000 -i 5000 http://yourbuild
     - npm run cypress -- --config baseUrl=http://yourbuild --spec ./**/yourspec1

 2-job:
   stage: acceptance-test
   script:
     - npm install
     - npm i -g wait-on
     - wait-on -t 60000 -i 5000 http://yourbuild
     - npm run cypress -- --config baseUrl=http://yourbuild --spec ./**/yourspec2

答案 4 :(得分:0)

enter image description here

我已经创建了orchestrator工具来做到这一点。它允许您部署任意数量的cypress docker容器并拆分所有规范,最后生成漂亮的HTML报告。

它是开源的,可以免费使用,您可以将其与Jenkins,TravisCI,github action或任何其他CI一起使用。

答案 5 :(得分:0)

Testery.io是一个基于云的测试平台,支持并行运行赛普拉斯测试。您可以注册一个免费计划,以并行运行最多5个测试,将执行集成到ci / cd系统中,并在平台上查看结果。如果选择付费计划,您还可以并行运行15-30个测试:https://testery.io/pricing

答案 6 :(得分:0)

如果你使用 Github Actions,我已经创建了这个并行运行测试的工作流,每次并行运行最多 15 个规范文件,所以它会在添加新测试时自动扩展。它可能会帮助您或其他人。这也使应用程序以 https 模式运行,但如果不需要,您可以删除这些行。

https://pastebin.com/ubx8BdUn

# This is a basic workflow to help you get started with Actions
name: Project
 
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [master, preprod, staging]
  pull_request:
    branches: [master, preprod, staging]
 
jobs:
  setup:
    runs-on: ubuntu-latest
    outputs:
      # will contain a json string with an array of n elements, each being a string of spec files delimited by ,
      test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
      # json string with ids to use in the next job matrix depending on how many elements are in the above array, eg: [0,1]
      test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
    steps:
      - uses: actions/checkout@v2
      - id: set-test-chunks
        name: Set Chunks
        # get all spec files from the integration directory, group them to be at most 15 at a time and transform them to json
        run: echo "::set-output name=test-chunks::$(find cypress/integration -type f -name "*.spec.js" | xargs -n15 | tr ' ' ',' | jq -R . | jq -s -cM .)"
      - id: set-test-chunk-ids
        name: Set Chunk IDs
        # get the number of elements from the above array as an array of indexes
        run: echo "::set-output name=test-chunk-ids::$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')"
        env:
          CHUNKS: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
 
  tests:
    needs:
      - setup
    runs-on: ubuntu-latest
    container:
      # use cypress image, since just using node 12 doesn't work currently for some reason, gives node-sass error
      image: cypress/browsers:node12.13.0-chrome78-ff70
      options: "--ipc=host" # fix for a cypress bug
    name: test (chunk ${{ matrix.chunk }})
    strategy:
      matrix:
        # will be for eg chunk: [0,1]
        chunk: ${{ fromJson(needs.setup.outputs['test-chunk-ids']) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
 
      - name: Add domain to hosts file
        run: echo "127.0.0.1 your.domain" | tee -a /etc/hosts
 
      # cache cypress and node_modules for faster operation
      -  uses: actions/cache@v2
         with:
           path: '~/.cache/Cypress'
           key: ${{ runner.os }}-cypress-${{ hashFiles('**/yarn.lock') }}
 
      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-docker-${{ hashFiles('**/yarn.lock') }}
 
      # in case cache is not valid, install the dependencies
      - run: yarn --frozen-lockfile
      - run: yarn run cypress install
 
      # run the frontend server in background and wait for it to be available
      - run: PORT=443 HTTPS=true yarn ci-start &
      - run: npx wait-on https://your.domain --timeout 180000
 
      # the cypress docker doesn't contain jq, and we need it for easier parsing of json array string.
      # This could be improved in the future, but only adds ~2s to the build time
      - run: apt-get install jq -y
 
      - name: Run Cypress
        run: SPECS=$(echo $CHUNKS | jq -cMr '.[${{ matrix.chunk }}] | @text') && yarn cypress:ci --spec $SPECS
        env:
          NODE_TLS_REJECT_UNAUTHORIZED: 0
          CHUNKS: ${{ needs.setup.outputs['test-chunks'] }}
 
  testsall:
    if: ${{ always() }}
    runs-on: ubuntu-latest
    name: Tests All
    needs: tests
    steps:
      - name: Check tests matrix status
        if: ${{ needs.tests.result != 'success' }}
        run: exit 1