| | |

Cypress 24 ๐ŸŒฒ Parallelization โ€” Cypress Cloud and –parallel

โฑ๏ธ Estimated read: 12 min | |

Cypress runs one spec file at a time in a single browser by default. A suite with a hundred spec files therefore runs serially, and the wall-clock time is the sum of every spec’s duration. Parallelization is the feature that splits the spec files across several machines or CI containers, runs them simultaneously, and merges the results into one report. The mechanism is not local: Cypress parallelization requires a recorded run on Cypress Cloud, and the --parallel flag tells the Cypress binary to ask the cloud service which specs this machine should run.

This chapter covers the --parallel flag, the --record prerequisite it depends on, the --ci-build-id that groups the machines into one run, and the load-balancing strategy Cypress Cloud uses to distribute the specs. It also covers the alternative of running specs in parallel without Cypress Cloud by splitting the spec list manually, and the trade-offs between the two approaches. The sections that follow walk through the record-and-parallel pair, the build id that ties the machines together, the load balancing that decides the split, and the local alternative for teams that cannot use the cloud.

Key point: --parallel only works together with --record; the Cypress binary sends the spec list to Cypress Cloud, the cloud assigns each machine a subset of specs based on historical timing, and --ci-build-id is the identifier that groups all the machines of one CI run into a single parallel run.


Why parallelization exists

The serial suite problem. A Cypress spec file starts a browser, loads the application, and runs the tests. The startup cost is significant, and a suite with many spec files spends most of its wall-clock time waiting for browsers to boot and applications to load. Running the specs one after another on a single machine makes the CI pipeline slow, and a slow pipeline discourages frequent runs.

The machine-cost trade-off. The obvious fix is to run the specs on several machines at once. The naive versionโ€”splitting the spec list into equal chunksโ€”is easy to write and wrong in practice, because spec files do not take equal time. A chunk with three slow specs finishes long after a chunk with ten fast ones, and the slowest machine determines the total duration.

The historical-timing solution. Cypress Cloud records how long each spec took on previous runs and uses that history to balance the load. The machine that finishes early asks the cloud for another spec, and the cloud hands out the next spec from the remaining list. The result is a near-even finish time across the machines, which is the actual goal of parallelization.

The record dependency. The timing history lives on Cypress Cloud, and the cloud only has it if the runs are recorded. The --parallel flag is therefore not a standalone feature; it is the consumer of the data that --record produces. A team that runs with --parallel but not --record gets an error, and a team that runs with --record but not --parallel gets the history and the dashboard but no splitting.

The vendor lock-in trade-off. The record-and-parallel pair is a Cypress Cloud feature. Teams that cannot send test data to a third-party service use the local alternativeโ€”splitting the spec list manually across CI jobsโ€”which works without the cloud but loses the historical load balancing. The trade-off is between the convenience of the cloud’s balancing and the control of a local split.


a. The --record and --parallel pair

The --record flag uploads the run’s results to Cypress Cloud. The --parallel flag asks the cloud which specs this machine should run. The two flags are used together, and the --record flag is the prerequisite.

# Run with recording and parallelization
npx cypress run --record --parallel --key <record-key>

The --key is the project’s record key, found in the project settings on Cypress Cloud. It authenticates the run and ties it to the project. The key can also be set through the CYPRESS_RECORD_KEY environment variable, which is the recommended way in CI because it keeps the key out of the command line.

# The key from an environment variable
export CYPRESS_RECORD_KEY=<record-key>
npx cypress run --record --parallel

The --record flag without --parallel uploads the results and gives the dashboard, the screenshots, and the videos, but runs the specs serially on the one machine. The --parallel flag without --record is an error, because the cloud has no run to attach the machine to.

# Serial run with recording (dashboard, no splitting)
npx cypress run --record --key <record-key>

# Parallel run (requires recording)
npx cypress run --record --parallel --key <record-key>

The --parallel flag is only meaningful when more than one machine runs the command. A single machine with --parallel still runs its assigned specs serially, and the cloud sees one machine and assigns it the whole list. The flag is the declaration that this machine is one of several in the same run.


b. The --ci-build-id and grouping the machines

Cypress Cloud groups the machines into one run by their build id. The --ci-build-id flag sets that id, and every machine in the same CI run uses the same value. The cloud collects the machines that share the id and treats them as one parallel run.

# The same build id on every machine of the CI run
npx cypress run --record --parallel \
  --ci-build-id "$CI_PIPELINE_ID" \
  --key <record-key>

The CI provider’s run identifier is the natural build id: the GitHub Actions GITHUB_RUN_ID, the GitLab CI_PIPELINE_ID, the CircleCI CIRCLE_WORKFLOW_ID. The cloud uses the id to merge the machines’ results, and a machine with a different id starts a separate run.

# GitHub Actions: a matrix of three machines, one build id
jobs:
  cypress:
    strategy:
      matrix:
        machines: [1, 2, 3]
    steps:
      - uses: cypress-io/github-action@v6
        with:
          record: true
          parallel: true
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          # The same run id for every matrix machine
          CYPRESS_CI_BUILD_ID: ${{ github.run_id }}

The CYPRESS_CI_BUILD_ID environment variable is the CI-friendly form of the flag. The cloud also accepts the CI provider’s built-in variables automatically when the provider is recognized, and the explicit build id is the way to control the grouping when the automatic detection is not the wanted behavior.

The run finishes when every machine has reported. The cloud waits for all the machines with the build id, merges their results, and marks the run complete. A machine that crashes without reporting leaves the run incomplete, and the cloud shows the missing machine in the dashboard.


c. The load balancing and the spec assignment

The cloud’s load balancing is dynamic. Each machine asks for a spec, runs it, reports the result, and asks for the next one. The cloud hands out the next spec based on the remaining list and the historical timings, so a fast machine that finishes early gets more specs and a slow machine gets fewer.

Machine 1: spec-a (30s) โ†’ spec-d (20s) โ†’ spec-g (15s)  โ†’ total 65s
Machine 2: spec-b (25s) โ†’ spec-e (25s) โ†’ spec-h (10s)  โ†’ total 60s
Machine 3: spec-c (40s) โ†’ spec-f (20s)                 โ†’ total 60s

The balance is not a static split. The first assignment is based on the historical timing from previous runs, and the later assignments adapt as the machines report. A machine that runs slower than its history gets fewer of the remaining specs, which is what keeps the finish times close.

The historical timing starts empty on a new project. The first recorded parallel run has no history, and the cloud falls back to the spec file order and the file sizes. The balancing improves as the project accumulates runs, and a project with a stable spec list converges to a near-even split after a few runs.

// cypress.config.ts: the spec pattern the cloud splits over
import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    // Only these specs are candidates for the parallel split
    specPattern: "cypress/e2e/**/*.cy.ts",
    // The videos and screenshots are uploaded with --record
    video: true,
    screenshotOnRunFailure: true,
  },
});

The specPattern is the list the cloud splits. A spec outside the pattern is not run in the parallel run, which is the way to exclude a spec from the split. The excludeSpecPattern option removes a spec from the list without changing the directory structure.


Complete Example Session

// ============================================
// PART 1: THE CONFIG
// ============================================
// cypress.config.ts
import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    specPattern: "cypress/e2e/**/*.cy.ts",
    video: true,
    screenshotOnRunFailure: true,
  },
});

// ============================================
// PART 2: THE LOCAL PARALLEL RUN
// ============================================
// The record key from the environment, not the command line
export CYPRESS_RECORD_KEY=<record-key>
npx cypress run --record --parallel --ci-build-id local-1

// ============================================
// PART 3: THE CI MATRIX
// ============================================
// .github/workflows/cypress.yml (excerpt)
jobs:
  cypress:
    strategy:
      matrix:
        machines: [1, 2, 3]
    steps:
      - uses: cypress-io/github-action@v6
        with:
          record: true
          parallel: true
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          CYPRESS_CI_BUILD_ID: ${{ github.run_id }}

// ============================================
// PART 4: THE MANUAL SPLIT (NO CLOUD)
// ============================================
# Split the spec list into two halves by line count
SPECS=$(find cypress/e2e -name "*.cy.ts" | sort)
HALF=$(echo "$SPECS" | wc -l)
echo "$SPECS" | head -n $((HALF / 2)) > specs-a.txt
echo "$SPECS" | tail -n +$((HALF / 2 + 1)) > specs-b.txt

# Machine A runs the first half
npx cypress run --spec "$(cat specs-a.txt | tr '\n' ',')"

// ============================================
// PART 5: THE SPEC PATTERN EXCLUSION
// ============================================
// cypress.config.ts
export default defineConfig({
  e2e: {
    specPattern: "cypress/e2e/**/*.cy.ts",
    // A spec excluded from the parallel split
    excludeSpecPattern: "cypress/e2e/flaky/**/*.cy.ts",
  },
});

The parts covered the config, the local parallel run, the CI matrix that runs the machines, the manual split for teams without the cloud, and the spec pattern exclusion.


Quick Reference

The Flags

FlagEffect
--recordUpload results to Cypress Cloud
--parallelAsk the cloud for this machine’s specs
--keyThe project record key
--ci-build-idThe id that groups the machines
--groupA label for a subset of machines

The Environment Variables

VariableEquivalent Flag
CYPRESS_RECORD_KEY--key
CYPRESS_CI_BUILD_ID--ci-build-id

The Trade-Offs

ApproachBalancingRequirement
Cloud parallelHistorical timingCypress Cloud account
Manual splitEqual chunksLocal script
Serial recordNoneCypress Cloud account

Best Practices

โœ… Do This:

// Use the record and parallel flags together
npx cypress run --record --parallel --key <key>;              // โœ…

// Keep the key in an environment variable
export CYPRESS_RECORD_KEY=<key>;                              // โœ…

// Use the CI run id as the build id
--ci-build-id "$CI_PIPELINE_ID"                               // โœ…

// Use a matrix of machines in CI
matrix: { machines: [1, 2, 3] }                               // โœ…

โŒ Don’t Do This:

// Use parallel without record
npx cypress run --parallel;                                   // โŒ

// Put the record key in the command line
npx cypress run --record --key abc123;                        // โŒ

// Use a different build id per machine
--ci-build-id "$RANDOM"                                       // โŒ

// Split specs by equal count (not equal time)
head -n 10 specs.txt                                          // โŒ

Common Pitfalls

PitfallWhy It HappensFix
Parallel flag errorsNo --recordAdd --record
Run never completesA machine did not reportCheck the matrix job
Uneven finish timesNo timing history yetRun a few times
Specs not splitDifferent build idsUse one CI run id
Key exposedKey in the command lineCYPRESS_RECORD_KEY

Real-World Examples

1. Local parallel run

npx cypress run --record --parallel --key $KEY

2. Build id from CI

npx cypress run --record --parallel --ci-build-id $CI_PIPELINE_ID

3. GitHub Actions matrix

strategy: { matrix: { machines: [1, 2, 3] } }

4. Record without parallel

npx cypress run --record --key $KEY

5. Spec pattern

specPattern: "cypress/e2e/**/*.cy.ts"

6. Spec exclusion

excludeSpecPattern: "cypress/e2e/flaky/**/*.cy.ts"

7. Group label

npx cypress run --record --parallel --group smoke

8. Manual split

npx cypress run --spec "$(cat specs-a.txt | tr '\n' ',')"

9. Record key env

export CYPRESS_RECORD_KEY=<record-key>

10. Build id env

export CYPRESS_CI_BUILD_ID=$GITHUB_RUN_ID

Visual

The Record and Parallel Pair

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  --record                  --parallel                   โ”‚
โ”‚      โ”‚                         โ”‚                        โ”‚
โ”‚      โ–ผ                         โ–ผ                        โ”‚
โ”‚  upload results          ask for specs                  โ”‚
โ”‚      โ”‚                         โ”‚                        โ”‚
โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚
โ”‚                 โ–ผ                                       โ”‚
โ”‚           Cypress Cloud                                 โ”‚
โ”‚           timing history + spec assignment              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Machine Grouping

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  CI RUN  (build id: 1234)                               โ”‚
โ”‚                                                         โ”‚
โ”‚  machine 1 โ”€โ”€โ”                                          โ”‚
โ”‚  machine 2 โ”€โ”€โ”ผโ”€โ”€โ–บ Cypress Cloud โ”€โ”€โ–บ one merged run      โ”‚
โ”‚  machine 3 โ”€โ”€โ”˜                                          โ”‚
โ”‚                                                         โ”‚
โ”‚  A different build id starts a separate run.            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Dynamic Assignment

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  machine 1: spec-a โ†’ spec-d โ†’ spec-g                    โ”‚
โ”‚  machine 2: spec-b โ†’ spec-e โ†’ spec-h                    โ”‚
โ”‚  machine 3: spec-c โ†’ spec-f                             โ”‚
โ”‚                                                         โ”‚
โ”‚  Each machine asks for the next spec when it finishes.  โ”‚
โ”‚  The cloud balances by the historical timings.          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Manual Split

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  all specs โ”€โ”€โ–บ script โ”€โ”€โ–บ chunk A โ”€โ”€โ–บ machine A         โ”‚
โ”‚                     โ””โ”€โ”€โ”€โ–บ chunk B โ”€โ”€โ–บ machine B         โ”‚
โ”‚                                                         โ”‚
โ”‚  No timing history. Equal chunks, not equal time.       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Parallel flag--parallel
Record flag--record
Record key--key or CYPRESS_RECORD_KEY
Build id--ci-build-id or CYPRESS_CI_BUILD_ID
Group label--group
BalancingHistorical timing on the cloud
Spec listspecPattern
ExclusionexcludeSpecPattern

Key takeaways:

  • --parallel requires --record. The cloud needs the recorded run to attach the machines to, and the timing history that the balancing uses is a product of the recording.
  • The build id groups the machines. Every machine in the same CI run uses the same --ci-build-id, and a machine with a different id starts a separate run.
  • The balancing is dynamic. Each machine asks for the next spec when it finishes, and the cloud hands out the specs based on the historical timings, which is what keeps the finish times close.
  • The first runs are unbalanced. A new project has no timing history, and the cloud falls back to the spec order. The balancing converges after a few recorded runs.
  • The manual split is the alternative. Teams that cannot use Cypress Cloud split the spec list into chunks in a script, which works without the cloud but does not balance by time.

Remember: Cypress parallelization is a pair of flags, not a single one. The --record flag uploads the results and the timing history, the --parallel flag asks the cloud for this machine’s specs, and the --ci-build-id groups the machines into one run. The cloud’s dynamic assignment is the value over a manual split, because it balances by the actual spec durations rather than the spec count. Use the cloud when the account is available, use the manual split when it is not, and never use --parallel without --record.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!