Parallel Cypress tests on TeamCity

喜欢而已 提交于 2020-02-01 09:24:46

问题


We currently have a repo containing 24 integration/*.js files. We are successfully running Cypress tests via our TeamCity CI workflow, however, I am unable to get the tests to run in parallel.

By way of configuration, we have the repo/tests wired up to an org in dashboard.cypress.io. Along with the dashboard key, we are calling Cypress in a TeamCity build step via npm run with the following configs in our package.json scripts{} :

"cypress:run:qa": "cypress run -c cypress.qa.json --record --key xyxyxyx-xyxyx-xyxyx-xyxyx-xyxyxyxyxyxy --parallel --config baseUrl=\"https://some.url.com\" --ci-build-id=%BUILD_ID_CYPRESS%"

The %BUILD_ID_CYPRESS% environment var being passed in above is a custom combination of the TeamCity build ID and number, to make it unique.

The package.json has the following dependencies listed:

"devDependencies": {
    "cypress": "^3.3.2",
    "cypress-plugin-retries": "^1.2.0"
  },
  "dependencies": {
    "ldclient-electron": "^1.0.1",
    "ldclient-js": "^2.10.0",
    "ldclient-node": "^5.7.4"
  }

The cypress.qa.json config file contents are:

{
  "projectId": "*redacted*",
  "baseUrl": "https://some.url.com",
  "numTestsKeptInMemory": 50,
  "port": 3002,
  "reporter": "teamcity",
  "reporterOptions": null,
  "watchForFileChanges": true,
  "viewportWidth": 1280,
  "viewportHeight": 720,
  "defaultCommandTimeout": 30000,
  "execTimeout": 90000,
  "taskTimeout": 90000,
  "pageLoadTimeout": 60000,
  "requestTimeout": 60000,
  "responseTimeout": 60000,
  "screenshotsFolder": "cypress/screenshots",
  "trashAssetsBeforeRuns": true,
  "videoCompression": 32,
  "videosFolder": "cypress/videos",
  "video": true,
  "videoUploadOnPasses": false,
  "env": {
    "retryAttempts": "2",
    "*redacted URL Name*": "https://some.otherURL.com/someSubDirectory/"

  }

  }

In TeamCity, I see the following output in the build log, which seems to indicate that the Cypress is passing along the parallel configs correctly:

[15:48:08]  [Step 8/11] ================================================================================
[15:48:08]  [Step 8/11] 
[15:48:08]  [Step 8/11]   (Run Starting)
[15:48:08]  [Step 8/11] 
[15:48:09]  [Step 8/11]   ┌────────────────────────────────────────────────────────────────────────────�
[15:48:09]  [Step 8/11]   │ Cypress:  3.4.0                                                            │
[15:48:09]  [Step 8/11]   │ Browser:  Electron 61 (headless)                                           │
[15:48:09]  [Step 8/11]   │ Specs:    24 found (**spec names redacted*** │
[15:48:09]  [Step 8/11]   │ Params:   Group: false, Parallel: true                                     │
[15:48:09]  [Step 8/11]   │ Run URL:  https://dashboard.cypress.io/#/projects/*redactedProjID*/runs/26           │
[15:48:09]  [Step 8/11]   └────────────────────────────────────────────────────────────────────────────┘
[15:48:09]  [Step 8/11] 
[15:48:09]  [Step 8/11] 2019-07-23T15:48:10.502Z cypress:server:record before spec run { spec: undefined }
[15:48:09]  [Step 8/11] 2019-07-23T15:48:10.503Z cypress:server:api request to url: POST https://api.cypress.io/runs/*redactedGUID*/instances with params: {"body":{"spec":null,"groupId":"win32-Electron-61-abcabcabc","machineId":"**RedactedMachineID","platform":{"osCpus":[{"model":"Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz","speed":2400,"times":{"user":*redacted*,"nice":0,"sys":*redacted*,"idle":*redacted*,"irq":*redacted*}},{"model":"Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz","speed":2400,"times":{"user":*redacted*,"nice":0,"sys":*redacted*,"idle":8866723484,"irq":517593}}],"osName":"win32","osMemory":{"free":956882944,"total":4294557696},"osVersion":"6.3.9600","browserName":"Electron","browserVersion":"61.0.3163.100"}},"headers":{"x-route-version":"5","x-os-name":"win32","x-cypress-version":"3.4.0"}} and token: undefined
[15:48:09]  [Step 8/11] 2019-07-23T15:48:10.624Z cypress:server:api response { spec: 'cypress\\integration\\*redacted*.js', instanceId: '*redactedGUID*', claimedInstances: 1, totalInstances: 24, estimatedWallClockDuration: 675698 }

However, the same machineId is repeated through the log output of each subsequent test run, all of which run serially on the same TeamCity agent.

We are not doing anything fancy with test grouping in Cypress, nor anything else particularly unique, that I can see, but the Cypress runs continue to execute serially.

I'm specifically concerned there is either:

  • A TeamCity config I'm missing (there is no specific documentation on the TeamCity or Cypress side regarding a TeamCity/Cypress integration that I can find)
  • An obvious omission in my Cypress config above that hopefully some kind stranger can call out.

回答1:


I am not sure of your approach. But there are few other options.

One way is to run tests using docker-compose on TC. Here is an example project. This script will create a docker image for your project and run multiple instances of your image.

https://github.com/SgSridhar/cypress-docker-parallel-tests/blob/master/package.json#L25

I have been spiking on this for a while. Cypress github actions seems to be the best choice to run tests in any mode you want.

https://github.com/SgSridhar/cypress-docker-parallel-tests/commit/d49db3edfe1ee59bc42d990c708152d98350f411/checks?check_suite_id=375441436

I would recommend to take github actions approach. You can save tons of time.



来源:https://stackoverflow.com/questions/57168488/parallel-cypress-tests-on-teamcity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!