Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to stores the data in .as command but its returning Null when recalled using This.text

I’m trying to store a variable using .as command which stores the data but its returning Null when recalled using This.text

it('store variable',function(){

cy.log('ASDF').as('print')
}

it('print',function(){
cy.log(This.print)
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s because cy.log() does not yield anything. Look at the docs, each command has a Yields section to let you know what gets passed to chained commands like .as().

You want to use cy.wrap() instead.

cy.wrap('ASDF').as('print')

Also don’t use a capital T on this

cy.log(this.print)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading