DEV Community

Discussion on: Page Object Pattern + Reusable Functions in Cypress

Collapse
 
nenad_cvet profile image
Nenad Cvetković

How did you solve verification / assertion?

Collapse
 
nikomadar profile image
Niko • Edited

You can still do assertions if you write your elements in the POM class to return the cy objects.

Example:
usernameField(){
return cy.get(#username)
}

And then in your test file you can just chain cy commands of it.

loginPage.usernameField().should('be.visible')

Collapse
 
ajdinmust profile image
Ajdin Mustafić

Hi Nenad! Thanks for the question. If needed, I assert directly in the function, so it is completely standalone.

Collapse
 
nikomadar profile image
Niko • Edited

I prefer to do the assertions in the test file. Becuase then the POM element can be used for various assertions without having to duplicate them.
Also the test should be where all the checks take place. If the check is in an external function then we lose test clarity.