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

cy.as() command can't share object between tests? #15593

Closed
alex-vungle opened this issue Mar 20, 2021 · 1 comment
Closed

cy.as() command can't share object between tests? #15593

alex-vungle opened this issue Mar 20, 2021 · 1 comment

Comments

@alex-vungle
Copy link

alex-vungle commented Mar 20, 2021

Not sure if this is the correct place to raise this isssue.

In my test code, I would like to share the response body data yielded from the command cy.createApp() between tests, however, when I executed this spec file, I noticed in test 01, it can print the value that's stored in app_data, in test 02, it print nothing, I can not reference any field stored in app_data in test 02, it seems before the code goes to test 02, the alias app_data was cleared by cypress runner.

Could you pls let me know if this is a bug or a limitation of Cypress? BTW, the Cypress version I'm using is 6.8.0

Thanks in advance!

describe('Foo', function() 
{
    before('Prepare test account', function() {
        cy.log('Generate a new test account')
        cy.task('generateNewAccount', {account_type: 'test'}).then((email)=>{
           cy.login(email, 'account')
           cy.saveLocalStorage()
        })
        cy.log('Create a default iOS app for the account')

        cy.createApp('iOS Test App', 'ios').then(($appdata) => {
            cy.wrap($appdata).as('app_data')
        })

    })

    it('test 01', function () {
        cy.log(this.app_data) //Print the detailed info
    })

    it('test 02', function() {
        cy.log(this.app_data) //Print nothing
    })

}
@jennifer-shehane
Copy link
Member

Duplicate of #665

@jennifer-shehane jennifer-shehane marked this as a duplicate of #665 Mar 20, 2021
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

2 participants