Skip to main content

Command Line Arguments

We use three CLI arguments and control our app with them.

namerequireddefaultdescription
productyesnullProject you want to run
envnostagingEnvironment you want to run
typenonullName of the config you want to use

You may have noticed in package.json that we have 6 new commands injected to run our project with.

Three of those are for open mode, and three of those are for headless mode.

./package.json
"scripts": {
"saucedemo-staging": "cypress run -e product=saucedemo,env=staging",
"saucedemo-staging.open": "cypress open --e2e -e product=saucedemo,env=staging",
"saucedemo-release": "cypress run -e product=saucedemo,env=release",
"saucedemo-release.open": "cypress open --e2e -e product=saucedemo,env=release",
"saucedemo-production": "cypress run -e product=saucedemo,env=production",
"saucedemo-production.open": "cypress open --e2e -e product=saucedemo,env=production",
}

This naming convention helps us to keep things intuitive and simple.

Or if you need to add your own custom parameters:

$ npx cypress run -e product=saucedemo,env=staging,myParameter="myTestValue"

Arguments

Lets go trough each argument and what it is used for.

product

Required: yes

Description:

This argument defines the project you want to run.

Example:

$ npx cypress run -e product=saucedemo

We will load files only from shared directories and saucedemo/ directories.

This means that if you have multiple projects set up, only commands, fixtures, and configs from that project will be loaded.

info

This way we avoid command and git conflicts between projects.

env

Required: no

Default: staging

Description:

The environment argument defines what routes and users we use.

Example:

$ npx cypress run -e product=saucedemo,env=production

This way we run the tests against the production environment.

type

Required: no

Default: null

Description:

With this argument we define with what config should the global cypress config be extended with.

Example:

$ npx cypress run -e product=saucedemo,env=production,type=smoke
info

We will see how to use the type argument in the next step.

CI/CD

Running in the pipeline, you might want to have more flexibility with the parameters, and therefor you can run your project without the use of package.json scripts:

$ npx cypress run -e product=saucedemo,env=staging,myParameter="myTestValue"