简体   繁体   English

TeamCity 上的并行 Cypress 测试

[英]Parallel Cypress tests on TeamCity

We currently have a repo containing 24 integration/*.js files.我们目前有一个包含 24 个integration/*.js文件的 repo。 We are successfully running Cypress tests via our TeamCity CI workflow, however, I am unable to get the tests to run in parallel.我们通过 TeamCity CI 工作流成功运行 Cypress 测试,但是,我无法并行运行测试。

By way of configuration, we have the repo/tests wired up to an org in dashboard.cypress.io.通过配置,我们将 repo/tests 连接到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{} :除了仪表板键,我们还在 TeamCity 构建步骤中通过npm run调用 Cypress,并在package.json scripts{}使用以下配置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.上面传入的 %BUILD_ID_CYPRESS% 环境变量是 TeamCity 构建 ID 和编号的自定义组合,以使其独一无二。

The package.json has the following dependencies listed: package.json列出了以下依赖项:

"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: cypress.qa.json配置文件内容是:

{
  "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:在 TeamCity 中,我在构建日志中看到以下输出,这似乎表明 Cypress 正在正确传递并行配置:

[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.但是,在每次后续测试运行的日志输出中都会重复相同的machineId ,所有这些都在同一个 TeamCity 代理上连续运行。

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.我们并没有对 Cypress 中的测试分组做任何花哨的事情,也没有做任何我可以看到的特别独特的事情,但是 Cypress 运行继续串行执行。

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)我缺少的 TeamCity 配置(在 TeamCity 或 Cypress 方面没有关于我可以找到的 TeamCity/Cypress 集成的特定文档)
  • An obvious omission in my Cypress config above that hopefully some kind stranger can call out.上面我的 Cypress 配置中有一个明显的遗漏,希望有好心的陌生人可以指出。

I am not sure of your approach.我不确定你的方法。 But there are few other options.但几乎没有其他选择。

One way is to run tests using docker-compose on TC.一种方法是在 TC 上使用 docker-compose 运行测试。 Here is an example project.这是一个示例项目。 This script will create a docker image for your project and run multiple instances of your image.此脚本将为您的项目创建一个 docker 镜像并运行您的镜像的多个实例。

https://github.com/SgSridhar/cypress-docker-parallel-tests/blob/master/package.json#L25 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. Cypress github actions 似乎是以您想要的任何模式运行测试的最佳选择。

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

I would recommend to take github actions approach.我建议采用 github 操作方法。 You can save tons of time.您可以节省大量时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM