I'm trying to setup cypress on my local machine and run parallel tests. But I can't find some information how to do this.
-
Two days back I asked the same question to my software architect, he said it possible to run parallel cypress tests only in CI/CD pipeline, but not locally – soccerway Aug 09 '19 at 05:04
-
i found information about this in official site: Cypress can run recorded tests in parallel across multiple machines since version 3.1.0. While parallel tests can also technically run on a single machine, we do not recommend it since this machine would require significant resources to run your tests efficiently. https://docs.cypress.io/guides/guides/parallelization.html#Overview – Lev Boichenko Aug 09 '19 at 05:09
-
Yes they don't recommend it. – soccerway Aug 09 '19 at 05:13
-
but it is possible to do :) – Lev Boichenko Aug 09 '19 at 05:22
-
2Yes, But i haven't find any documentation from Cyress team. – soccerway Aug 09 '19 at 05:25
7 Answers
Technically, it's possible. Cypress does not recommend it since running multiple cypress instances on the same machine consumes lots of resources (CPU over all) and it slows down the entire machine performances with useless results.
Anyway if you have limited resources and you cannot use the official dashboard or you don't have more than one CI server available, you can run your test on a single machine launching cypress run multiple times dividing your test suite in multiple folders.
I've created a npm library called cypress-parallel
(https://github.com/tnicola/cypress-parallel) that (after the first run), balances and splits the test suite in multiple subsets, based on the tests run history and for each subset it launches a Cypress command. It also collect the results from all the specs file, logging them at the end of the execution. In terms of performances, it seems that with 2 processes you can improve your overall tests execution time time up to 40%.

- 547
- 6
- 10
-
1great job Nicola, I have tried to use it but got an error in console `env: node\r: No such file or directory` – Evgenii Bazhanov Jul 01 '20 at 08:28
-
1if you have any repo with a simple working example please let me know – Evgenii Bazhanov Jul 01 '20 at 08:43
-
2@EvgeniiBazhanov Are you running it on a Mac?I've tried to fix that, check out the new version 0.1.4 – Nicola Tommasi Jul 01 '20 at 09:07
-
yes on Mac but later I guess will do in cirlceci (Linux) thanks let me check – Evgenii Bazhanov Jul 01 '20 at 10:20
-
do you know how to avoid this error `Error: ENOENT: no such file or directory, scandir 'cypress/integration'` I am keeping my tests like `tests/cypress/e2e/admin/test.ts` – Evgenii Bazhanov Jul 01 '20 at 10:45
-
2Now you can pass your own spec folder: https://github.com/tnicola/cypress-parallel#scripts-options in v.0.1.5. Open an issue directly on the repo if something else is not working otherwise we'll spam all the people on this post. – Nicola Tommasi Jul 01 '20 at 14:30
-
-
ok this is the result `Weight file not found in path: cypress/parallel-weights.json npm WARN lifecycle The node binary used for scripts is /var/folders/gk/_t2pqg6167xc8wmbkl4nj_d40000gp/T/yarn--1593616287263-0.22055657138975082/node but npm is using /usr/local/Cellar/node@10/10.20.1/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with. ` – Evgenii Bazhanov Jul 01 '20 at 15:12
-
should I create this file manually `cypress/parallel-weights.json` because it really does not exist – Evgenii Bazhanov Jul 01 '20 at 15:14
-
No, that file will be created automatically the first time. It seems it cannot launch npm scripts from node. How did you run it? – Nicola Tommasi Jul 01 '20 at 15:18
-
3with yarn actually, maybe I should create an issue in your repo with more details https://github.com/tnicola/cypress-parallel/issues the problem is I am trying to implement your library in our working project so I need to create another simple project with anonymized data – Evgenii Bazhanov Jul 01 '20 at 15:56
-
1This answer makes me think that Cypress needs work on memory optimization by the dev team, in order to be competitive in the testing market. – djangofan Nov 29 '21 at 18:03
Well, I kinda run them parallel locally. Some thoughts to use:
- I have a MacBook, so it's implemented for iOS.
- My application runs in a Docker container, I only need one instance to run multiple tests at the same time. Via my terminal I created multiple files splitting the specs into seperate .command-files like this:
echo "cd <PROJECT_DIRECTORY> && npx cypress run --spec cypress/integration/<SPECS_DIRECTORY>/*" > cypress.command; chmod +x cypress.command
You can stack multiple directories/files behind the--spec
, thus--spec cypress/integration/<SPECS_DIRECTORY>/* cypress/integration/<SPECS_DIRECTORY2>/*
is also valid. - Lets say I have 2 of those .command-files. I can start those with this command:
open cypress-01.command cypress-02.command
- This will launch two separate terminals, both running the specs mentioned in each file.
This reduced my runtime for the local tests from 1,5h to 15 minutes.

- 3,499
- 1
- 11
- 25
A) The most "naive" (1minute and done) solution assuming you are on linux/macOs that actually worked somewhat decently (just to re-run regression locally) to have a bash script with simple &
at the end
# 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 &
B) But if you want something tiny bit more "sophisticated" continue reading on :
However in our test we run same regression on 4 datacenters (aws,gc) and on each we run multiple brands (some are for redundancy, some are specific to that DC location) so for our needs we don't need a specs balancing. Rather parallel the cypress processes.
So far it seems for this to work well, you need couple of pre-requisites as you can read here. We've had to solve few issues.
- Xvfb race condition
- have ability to limit the amount of threads
- profile locking issue
- image access issues
- starting the Xvfb prior running our parallel run script.
# 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
- There are better more robust solutions out there but this seems to have worked for us.The bash above runs the
main.js
below. Each Array of brands is executed in parallel butawait
ed execution of each seriesforEachSeries
, without it you would just run everything in parallel (instead of 2 you'd have 4threads
). So as long as you can create an array the amount 1st-level arrays will define the amount of parallel threads. You can google search for balanced arrays function and use it for balancing the array and if you decide to balance specs instead of "brands" as we do below, you just need to modify the command passed toawaitedSpawn()
with something likeXDG_CONFIG_HOME=/tmp/cyhome${cfg.id} cypress run --spec {cfg.spec}
.
// main.js
// this part is synchronous
if (run.THREADS_NO >= 2) {
// 2 threads with 2 brands each
const threads = {[[brand: "brand1"],[brand: "brand2"],[[brand: "brand3"],[brand: "brand4"]]};
threads.forEach((threadBrandInfo) => {
asyncWrapper(threadBrandInfo);
});
}
// async_stuff.js
// courtesy of https://github.com/toniov/p-iteration
exports.forEachSeries = async (array, callback, thisArg) => {
for (let i = 0; i < array.length; i++) {
if (i in array) {
await callback.call(thisArg || this, await array[i], i, array);
}
}
};
const awaitedSpwan = async (cmd) => {
const child = await exec(cmd);
return new Promise((resolve, reject) => {
child.on('close', (code) => {
if (code === 0) {
resolve(child.stdout);
} else {
const err = new Error(child.stdout,child.stderr);
reject(err);
}
});
});
}
const asyncWrapper = async (brandsConfigs) => {
forEachSeries(brandsConfigs, async (cfg) => {
await awaitedSpawn(`XDG_CONFIG_HOME=/tmp/cyhome${cfg.brand} cypress run`)
.then((res) => {
console.log(res);
return res;
})
.catch((e) => {
console.error(e.stderr);
});
});
};
This part of the code above solves that issue
XDG_CONFIG_HOME=/tmp/cyhome1
Simply set the cypress env var
trashAssetsBeforRuns=false
one way of doing that is using cypress.json or as in the bash script in1)

- 136
- 1
- 3
I have created a npm tool called orchestrator
(https://github.com/0xIslamTaha/orchestrator) to be able to run all your specs in one machine. It uses docker underneath and it splits all specs across multiple docker machines.
Features:
- Open source.
- Automatically split all specs.
- Support multiple browsers.
- Generate a handsome HTML report.
- Easy Configurable.
- Working great with docker.
- Fully documented.
- There is an open-source use case repo (ready to go).
Articles:
- Cypress parallelization with the Orchestrator — part 1
- Cypress parallelization with the Orchestrator — part 2 — ShowCase
Show Cases:

- 1,056
- 1
- 10
- 17
On Linux, you can use GNU parallel. Then you can run Cypress on 8 cores for example with:
find cypress/integration/ -name '*.js' | parallel -j8 npx cypress run --spec {}
Add --tty
parameter to keep colors. Add --group
to have outputs not mixed. I did not achieve to use those two parameters at the same time and keep colors though.

- 218
- 2
- 10
Bazel+rules_nodejs is capable of running multiple cypress tests in parallel on the same machine. But, the experience of writing cypress tests in bazel will be quite different than you are used to.
https://github.com/bazelbuild/rules_nodejs/tree/2.0.0-rc.3/examples/cypress

- 595
- 6
- 6
Try This, but this could halt your system
Add it to your Package.json and run "npm run cy:runBrowsers"
"cy:runSpec" : "npx cypress run --spec 'cypress\\e2e\\ecommerceDemo\\*' --headed",
"cy:runBrowsers": "npm run cy:runSpec -- --browser chrome | npm run cy:runSpec -- --browser edge"

- 109
- 7