Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access nested values in Cypress.json

Tags:

cypress

Cannot access nested values in Cypress.json file.

I have just started learning Cypress and trying to organise some variables into the Cypress.json file.

The usual dot and bracket notation do not work because the key is already in single/double quotes, so I think Cypress sees it as a complete string eg. (Cypress.env('login.username')).

This is my simple Cypress.json file

{
   "env":{
    "login":{
        "username":"Joe"
        }
   }
}

How can I access the name Joe?

like image 543
newcasio Avatar asked Dec 14 '22 10:12

newcasio


1 Answers

Try this, it will return the username.

Cypress.env('login').username // returns "Joe"

Read more about Environment Variables

like image 185
Yevhen Laichenkov Avatar answered Dec 31 '22 14:12

Yevhen Laichenkov