samedi 15 août 2020

In Cypress.io can I copy a content from one element and past it into another one(for example into form)?

I already checked the Cypress.io FAQ: https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-get-an-element%E2%80%99s-text-contents

And with those tips I tryed by myself but it failed.

I want to get an element, grab it content, put it into variable, and use it later.

I want to achive same result like in Selenium element.getText().

describe("Training Test Room Suite", () => {

    it("Copy content from an element and past it  into next one", () => {
        let contentText
        cy.visit("http://the-internet.herokuapp.com/login");
        cy.get(".example > h2").should(($h2) => {
            contentText = $h2.text()
        })
        cy.get("#username").type(contentText);
    })

})

CypressError: cy.type() can only accept a string or number. You passed in: undefined

In above code, Im trying to copy text from the H2 , put it in the variable contentText, and paste it into input "username". Everything on a demo application http://the-internet.herokuapp.com/login

Can some one help me pls :)

Aucun commentaire:

Enregistrer un commentaire