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

Constant changes its value within the script visiting cross-domain URLs #20050

Closed
vovcharenko1 opened this issue Feb 4, 2022 · 4 comments
Closed

Comments

@vovcharenko1
Copy link

vovcharenko1 commented Feb 4, 2022

Current behavior

  1. Create a spec file having 3 tests:
  2. Declare a constant which gets its value from a calculation (e.g. as a timestamp or Math.random) as a global
  3. Create 3 tests. Each of the test logs out the constant first and then visit cross-domain URL
  4. Run the test

Expected result: The test log contains 3 same values of the constant.
Actual result: The test log contains 3 different values of the constant.

  1. Remove cy.visit() commands or replace them with the same domain URL
  2. After this the constant values are the same

Desired behavior

A constant should not change its value in any case

Test code to reproduce

const timeStamp = now().toString();
const businessEmail = `user${timeStamp}`;

describe('Smoke tests', ()=> {
    it('Create temporary email', () => {
        cy.log(businessEmail);
        cy.visit('https://ahem-email-api.datapwn.com/');
    })

    it('Create a trial account', ()=> {
        cy.log(businessEmail);
        cy.visit('https://google.com');
    })

    it('Register with temporary email', () => {
        cy.log(businessEmail);
        cy.visit('https://ahem-email-api.datapwn.com/')
    })
})```

### Cypress Version

8.7.0

### Other

![screen-1](https://user-images.githubusercontent.com/90378456/152497423-0f4dc77c-1c47-499a-97a3-86bef8a6130b.png)
@vovcharenko1
Copy link
Author

screen-1

@flotwig
Copy link
Contributor

flotwig commented Feb 8, 2022

@vovcharenko1 this is a natural consequence of the way Cypress currently works - it only supports visiting 1 superdomain per test: #944 Navigating between superdomains is not explicitly supported. You'll lose your local variables because Cypress has to reload window.top on cy.visit to a new superdomain.

Once multi-domain #17336 is added, you will be able to execute code in a second domain and pass in data from the primary domain.

@Srikanth07482
Copy link

Is there any alternative to use variables across domains without values getting changed? @flotwig

@mazhuga
Copy link

mazhuga commented Oct 28, 2022

Is there any alternative to use variables across domains without values getting changed? @flotwig

any updates here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants