Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress.env() state is not reset on rerun of test #6010

Open
jennifer-shehane opened this issue Dec 19, 2019 · 13 comments
Open

Cypress.env() state is not reset on rerun of test #6010

jennifer-shehane opened this issue Dec 19, 2019 · 13 comments
Labels
E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: breaking change Requires a new major release version type: unexpected behavior User expected result, but got another

Comments

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Dec 19, 2019

Current behavior:

Cypress.env() state is only read in once when the runner starts. This causes any changes to Cypress.env() to not reset when you rerun a test.

Desired behavior:

Clean, fresh Cypress.env() for each rerun of a test.

Steps to reproduce: (app code and test code)

{
  "env": {
    "num": 2
  }
}
it('should set ENV var num', () => {
  cy.log(`${Cypress.env('num')}`) // logs 2, but 3 on rerun
  Cypress.env('num', 3)
  cy.log(`${Cypress.env('num')}`) // logs 3
})

Screen Shot 2021-02-05 at 3 15 22 PM

But if I rerun the test, the log is already 3 at the beginning.

Screen Shot 2021-02-05 at 3 15 05 PM

Versions

3.8.0

@wejendorp
Copy link

Nice writeup, I'm hitting the same issue, with both Cypress.config and Cypress.env.
This is still occuring in cypress@4.4.1.

The docs state that both env and config resets between both runs and test suites, neither of which is currently true.

@jennifer-shehane
Copy link
Member Author

This is still an issue in Cypress 6.4.0

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Feb 5, 2021
@greg-hoarau
Copy link

I think it's same issue (Cypress 8.3.0) :

{
  "env": {
    "num": 2
  }
}
it('should always logs 2', () => {
  cy.log(`${Cypress.env('num')}`) // logs 2, but 3 on rerun
})

it('should set ENV var num and logs 3', { env: { num: 3 } }, () => {
  cy.log(`${Cypress.env('num')}`) // logs 3
})

@ZampaglioneGaston
Copy link

ZampaglioneGaston commented Aug 23, 2021

Still an issue in 8.3.0. Really annoying that sometimes is actually works, and when rerunning it does not.

            cy.get(prodObj.allProdContainter).find((prodObj.productPic)).each(($el, index) => { //Picture

                cy.get($el)
                    .should('be.visible')
                    .invoke('attr', 'src')
                    .then($src => {
                        cy.log($src);  //This logs my img src
                        Cypress.env('ImageUrl', $src)
                        cy.log(Cypress.env('ImageUrl' + [index])); //Yet here it does not. Sometimes it works, sometimes not.
                    })
                    
                cy.log('Product have picture.');

            })

Issue

EDIT: Found a workaround adding Cypress.env('ImageUrl'+ [index], $src)

@varshanharshank
Copy link

yes . still this issue persists in 9.2 version

@Elgirhath
Copy link

Still an issue in 9.3.1. Any updates on this?

@sandippatel84
Copy link

is there solution out? I'm hitting same in 9.2/3. thx

@firmanserdana
Copy link

firmanserdana commented Apr 5, 2022

Still an issue on 9.5.3

is there a way to just reload the runner once an env file is changed? Not just re-opening it.

@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Apr 28, 2022
@GastonZ-MayorKeyTech
Copy link

I can't believe this is still an issue

@tainalopes
Copy link

still an issue and it's very annoing :(

@zachwhite99
Copy link

This is still an issue. Even setting an afterTest block with Cypress.env('user', null/undefined) doesn't always work. Can we promote this somehow and get it addressed?

@nagash77
Copy link
Contributor

@zachwhite99 which version of Cypress are you using? If you aren't already using a version of Cypress >12 please try upgrading to latest and seeing if the problem persists.

@nagash77 nagash77 assigned nagash77 and unassigned nagash77 Apr 21, 2023
@nagash77 nagash77 added type: breaking change Requires a new major release version Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. E2E Issue related to end-to-end testing labels May 30, 2023
@samixchoumi
Copy link

Hello, "cypress": "^12.17.4", still the problem. It's not reset after each test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: breaking change Requires a new major release version type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests