简体   繁体   中英

How to Read Configurations from Property File in Cypress?

'.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?

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM