dimanche 25 mars 2018

Grab a string to use in a .visit() call in cypress

I have a dom element that contains the string or a url that I would like to visit. I have labelled the dom element with a data attribute for easy reference.

enter image description here

Above where it says 'Create Topic' in bold is the string and in the console, you can see it has a data-test='topicUrl attribute.

I want to capture this string value so that I can visit the url a a later point.

I followed the docs on Variables and Aliases and tried

cy.get('[data-test="topicUrl"]').invoke('text').as('Url')

so that I could visit the page by using

cy.visit(this.Url)

But that doesn't work, it errors out with TypeError: Cannot read property 'Url' of undefined in the console.

How do I grab the text in a DOM element so that I can use it to visit a url at a later point?

Aucun commentaire:

Enregistrer un commentaire