Reputation: 101
I need to get text from html element to use it in other checking.
But this checking must be done elsewhere later, not inside function of text getting.
That's why such variant as
> cy.get('#at__title').invoke('text').then((storedValue) => {
> storedValue
> })
doesn't suite, because I can use text only inside then
.
Also I tried to use
> cy.get('#at__title').invoke('text').as('element_text')
> this.element_text
but console log shows this.element_text
as undefined.
Upvotes: 1
Views: 54
Reputation: 31904
Using an alias is correct cy.get('#at__title').invoke('text').as('element_text')
but to access the value like this
this.element_text
requires the test to not be an arrow function.
Use this format
it('test something', function() {
this.element_text
Or use the longer syntax for accessing an alias
cy.get('@element_text').then(element_text => {
Upvotes: 1