Lev*_*nko 18 continuous-integration cypress
我正在尝试在本地机器上设置 cypress 并运行并行测试。但我找不到一些信息如何做到这一点。
Nic*_*asi 11
从技术上讲,这是可能的。Cypress 不推荐它,因为在同一台机器上运行多个 cypress 实例会消耗大量资源(总而言之是 CPU),并且会降低整个机器的性能并导致无用的结果。
无论如何,如果您的资源有限并且无法使用官方仪表板,或者您没有一个以上的 CI 服务器可用,您可以在一台机器上运行您的测试,启动 cypress run 多次,将您的测试套件划分到多个文件夹中。
我创建了一个名为cypress-parallel
( https://github.com/tnicola/cypress-parallel )的 npm 库,它(在第一次运行之后)根据测试运行历史记录和每个子集平衡和拆分测试套件子集它启动一个赛普拉斯命令。它还从所有规范文件中收集结果,并在执行结束时记录它们。在性能方面,似乎使用 2 个进程可以将整体测试执行时间缩短多达 40%。
好吧,我有点在本地并行运行它们。一些使用的想法:
echo "cd <PROJECT_DIRECTORY> && npx cypress run --spec cypress/integration/<SPECS_DIRECTORY>/*" > cypress.command; chmod +x cypress.command
您可以在.command
后面堆叠多个目录/文件--spec
,因此--spec cypress/integration/<SPECS_DIRECTORY>/* cypress/integration/<SPECS_DIRECTORY2>/*
也是有效的。open cypress-01.command cypress-02.command
这将我的本地测试运行时间从 1.5 小时减少到 15 分钟。
A)最“天真的”(1分钟完成)解决方案,假设您使用的是 linux/macO,实际上工作得不错(只是在本地重新运行回归),&
最后有一个简单的 bash 脚本
# to keep vid,pic could cause issue when trying to write and delete at the same time
export CYPRESS_trashAssetsBeforeRuns=false
XDG_CONFIG_HOME=/tmp/cyhome1 cypress run -spec cypress/integration/first.spec.js,cypress/integration/another1.spec.js &
XDG_CONFIG_HOME=/tmp/cyhome2 cypress run -spec cypress/integration/another2.spec.js,cypress/integration/another3.spec.js &
Run Code Online (Sandbox Code Playgroud)
B)但是如果你想要一些更“复杂”的东西,请继续阅读:
然而,在我们的测试中,我们在 4 个数据中心(aws、gc)上运行相同的回归,并且在每个数据中心上运行多个品牌(有些是为了冗余,有些是特定于该 DC 位置),因此根据我们的需求,我们不需要进行规格平衡。与柏树进程相当平行。
到目前为止,这似乎运作良好,您需要几个先决条件,您可以在此处阅读。我们必须解决一些问题。
# Start x11 server to avoid race condition in threads
Xvfb :96 &
# Make all cypress instances connect to the spawned x11
export DISPLAY=:96
# Read 4)
export CYPRESS_trashAssetsBeforeRuns=false
# read below (that's where the parallelization happens node.js 10+)
node ./main.js
Run Code Online (Sandbox Code Playgroud)
main.js
。每个品牌数组都是并行执行的,但await
每个系列的执行forEachSeries
都是并行执行的,如果没有它,您将只是并行运行所有内容(而不是 2 个,而是 4 个threads
)。因此,只要您可以创建一个数组,第一级数组的数量将定义并行线程的数量。您可以在谷歌上搜索平衡数组函数并使用它来平衡数组,如果您决定平衡规格而不是“品牌”,如下所示,您只需修改传递给的命令,awaitedSpawn()
例如XDG_CONFIG_HOME=/tmp/cyhome${cfg.id} cypress run --spec {cfg.spec}
.# to keep vid,pic could cause issue when trying to write and delete at the same time
export CYPRESS_trashAssetsBeforeRuns=false
XDG_CONFIG_HOME=/tmp/cyhome1 cypress run -spec cypress/integration/first.spec.js,cypress/integration/another1.spec.js &
XDG_CONFIG_HOME=/tmp/cyhome2 cypress run -spec cypress/integration/another2.spec.js,cypress/integration/another3.spec.js &
Run Code Online (Sandbox Code Playgroud)
# Start x11 server to avoid race condition in threads
Xvfb :96 &
# Make all cypress instances connect to the spawned x11
export DISPLAY=:96
# Read 4)
export CYPRESS_trashAssetsBeforeRuns=false
# read below (that's where the parallelization happens node.js 10+)
node ./main.js
Run Code Online (Sandbox Code Playgroud)
上面这部分代码解决了这个问题XDG_CONFIG_HOME=/tmp/cyhome1
只需设置 cypress 环境变量,trashAssetsBeforRuns=false
一种方法是使用 cypress.json 或如 bash 脚本中所示1)
归档时间: |
|
查看次数: |
12430 次 |
最近记录: |