Invalid Users

Before continuing, make sure you have read the Authentication Overview & Setup lesson first.

it("should error for an invalid user", () => {
  cy.login("invalidUserName", "invalidPa$$word")

  cy.getBySel("signin-error")
    .should("be.visible")
    .and("have.text", "Username or password is invalid")
  cy.visualSnapshot(
    "Sign In, Invalid Username and Password, Username or Password is Invalid"
  )
})

You can find out more information about the custom Cypress commands used in this test here.

First, we are using cy.login(), a Custom Cypress Command to use the Sign In UI to log in as a user with an invalid username and password.

cy.login("invalidUserName", "invalidPa$$word")

Finally, we confirm the error is displayed. The correct error message is shown with a chained expectation that the error is visible and has a specific error message.

cy.getBySel("signin-error")
  .should("be.visible")
  .and("have.text", "Username or password is invalid")