Reputation: 87
'.properties' files are mainly used to maintain project configuration data, database config or project settings etc. Each parameter in properties file are stored as a pair of strings, in key and value format, where each key is on one line. You can easily read properties from some file using object of type Properties.
Is there a way to Read Configurations from Property File in Cypress? Like in Selenium, we can read properties file, is there a way to do it in Cypress? If so, how?
Upvotes: 2
Views: 2275
Reputation: 7125
I'm interpreting your question as asking how you can store project-specific variables, not related to the actual configuration of Cypress. If that is true, then there are two fairly simple solutions to storing variables and referencing them in Cypress. (Cypress calls these environment variables)
Option 1: Storing them in cypress.json
. You'll store them in the env
object in your cypress.json
.
{
...
"env": {
"foo": "bar"
}
...
}
Option 2: Storing them in a separate cypress.env.json
file. These will just be a JSON file.
{
"foo": "bar"
}
In both cases, these values can be referenced in code by the following:
Cypress.env('foo');
Upvotes: 2