'How to use text from html-element in others non-cypres functions?

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.



Solution 1:[1]

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 => { 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fody