DannyMoshe
DannyMoshe

Reputation: 6265

cypress.json file not being recognized

I'm new to cypress and have created my first project with a cypress.json file in the root directory.

project directory

The contents of this file are as follows:

{
    "projectId": "bdld4"
    "env":{
        "host": "http://localhost:8000",
        "email": "[email protected]",
        "password": "obviouslyNotaRealPassword"
    }
}

Within the integration folder I have a test case which is attempting to access those environment variables:

Cypress.env('host')

This returns undefined. I have also tried this in cypress.env.json and have also tried placing the cypress.json file one level above the Cypress folder.

To run the tests, i'm using npx cypress open and selecting the test from the gui. Am I running the tests incorrectly or should the file be placed elsewhere? Any ideas?

Upvotes: 3

Views: 13315

Answers (2)

jeffkor
jeffkor

Reputation: 51

just FYI - Cypress no longer supports cypress.json. Use cypress.config.js instead.

I got an error when I had both a cypress.json and cypress.config.json file in my repo.

Upvotes: 3

Abhinaba
Abhinaba

Reputation: 424

the picture you have posted, cypress.json is not placed the root. It is inside the cypress folder.

  1. Either you can place the cypress.json one level up, I mean in the root of the project

  2. Or, you can pass the config file path parameter in your script, like:

npx cypress open --config-file cypress/cypress.json

Upvotes: 6

Related Questions