1

I am trying to apply the Page Object Model (POM) to some tests using Cypress.

Unfortunaly I can't read some webelement value and return it as a method or function value. I needed to make something like these to work:

var1 = cy.get("input#inpUserName").then(($var1) => {
    cy.log($var1.val());
})

cy.log(var1)

But all I could do was:

cy.get("input#inpUserName").then(($var1) => {
    cy.log($var1.val());
})

For what I researched I think there is no solution for that with Cypress. But I'd like to see if anyone has any suggestion about it.

1 Answer 1

0

You can return a value from a POM method, but it is Promise-like so you use .then() to access the value.

class Login {
  ...
  username() {
    return cy.get("input#inpUserName").then(($var1) => {
      return $var1.val()
    })
  }
}

...

const login = new Login()

login.username().then(username => {
  expect(username).to.eq('Joe')
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.