Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send baseUrl as a parameter with Cypress.io

Tags:

cypress

I am researching switching from Protractor to Cypress.io. I have some tests up and running, however, I want to be able to send the baseUrl as a parameter as I can with Protractor.

I have tried:

$ npm run cypress:open --config "baseUrl=myUrl" --still uses the baseUrl from my config file.

$ npm run cypress:open --env "baseUrl=myUrl" --still uses the baseUrl from my config file.

and a host of other things, none of which work quite right.

I want to be able to pass a parameter to my command which gives me the flexibility to choose which environment I am running my tests in. I can do this with Protractor, with a command like this:

$ ng e2e --suite testSuite --baseUrl myUrl

What is the equivalent for Cypress.io?

like image 341
DarthOpto Avatar asked Nov 27 '18 16:11

DarthOpto


People also ask

How do I run a specific spec in Cypress?

cypress run --spec <spec> Run tests specifying a single test file to run instead of all tests. The spec path should be an absolute path or can relative to the current working directory.


1 Answers

Brendan's answer is correct. I would like to add that

$ npm run cypress:open --config "baseUrl=myUrl"

may not be working since you try to propagate some configuration into a command inside your package.json. If instead you'd do for example:

$ ./node_modules/.bin/cypress run --config baseUrl=myUrl

it should work just fine.

This is good to know since it will let you use additional CLI options as well (which you do not know ahead of time).

PS: --env wouldn't work for baseUrl since baseUrl is a built-in configuration value and not a regular env variable.

like image 141
Erez Cohen Avatar answered Sep 18 '22 12:09

Erez Cohen