Skip to main content

Cypress Cookbook

Keep screenshots and videos​

Since Knapsack Pro runs Cypress multiple times, you need to set trashAssetsBeforeRuns to false.

You can do so by either invoking Knapsack Pro with:

npx @knapsack-pro/cypress --config trashAssetsBeforeRuns=false

Or in cypress.config.js:

{
"trashAssetsBeforeRuns": false
}

Component tests​

You can pass the testingType option to run component tests:

npx @knapsack-pro/cypress --testingType=component

Record CI builds in Cypress Dashboard​

export CYPRESS_RECORD_KEY=MY_RECORD_KEY

npx @knapsack-pro/cypress --record

If Cypress supports your CI, it will merge the tests executed on parallel nodes into a single run in the Cypress Dashboard using the CI build ID. Otherwise, you will need to specify it:

npx @knapsack-pro/cypress --record --ci-build-id $MY_CI_BUILD_ID

You should replace $MY_CI_BUILD_ID with the correct environment variable provided by your CI:

CI ProviderEnvironment Variable
AppVeyorAPPVEYOR_BUILD_NUMBER
BambooBAMBOO_BUILD_NUMBER
BuildkiteBUILDKITE_BUILD_NUMBER
CircleCIRCLE_WORKFLOW_ID
CirrusCIRRUS_BUILD_ID
CodeshipCI_BUILD_NUMBER
Codeship BasicCI_BUILD_NUMBER
Codeship ProCI_BUILD_ID
DroneDRONE_BUILD_NUMBER
GitlabCI_PIPELINE_ID
GitHub ActionsGITHUB_RUN_ID
HerokuHEROKU_TEST_RUN_ID
JenkinsBUILD_NUMBER
Semaphore 1.0SEMAPHORE_BUILD_NUMBER
Semaphore 2.0SEMAPHORE_WORKFLOW_ID
TravisTRAVIS_BUILD_ID
Codefresh.ioCF_BUILD_ID

Run a subset of tests​

To run a subset of your test suite you can use the KNAPSACK_PRO_TEST_FILE_* environment variables: