Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
Unable to see toast in cypress

I'm unable to see toast messages on cypress. Tried the test on browser and Command line. Also tried adding wait.

it('Login with invalid password', () => {
    login.enterEmail(testData.username)
    login.enterPassword(testData.invalidPassword)
    login.submit()
    cy.wait(2000)
    login.getToastError().contains(testData.invalidCredentialsError)
})

Any inputs regarding toast messages with cypress will be useful. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This worked for me when I was needing to verify it was present and had the correct message. I probably didn't need the selector in the .contains() but it works.

cy.get('ion-toast').should('exist').shadow().contains('.toast-message','Invalid username or password.');

The .shadow() method was the magic to see the internals of the toast.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem you face is that the toast appears slowly (compared to test running speed).

TLDR: Use cy.contains('my-selector', 'my-text')


Using cy.get('my-selector').contains('my-text') retries the text my-text, but not the existence of my-selector.

Using the format cy.contains('my-selector', 'my-text') will wait for the element to appear, then check it's text.

So, for a toast that has id="toaster"

it('Login with invalid password', () => {
    login.enterEmail(testData.username)
    login.enterPassword(testData.invalidPassword)
    login.submit()
    cy.contains('#toaster', testData.invalidCredentialsError)  
})

Or pass the error text into login.getToastError

it('Login with invalid password', () => {
    login.enterEmail(testData.username)
    login.enterPassword(testData.invalidPassword)
    login.submit()
    login.getToastError(testData.invalidCredentialsError)  
})
// login - approximate revision

getToastError(errorMessage) {
  if (errorMessage) {
    cy.contains('#toaster', testData.invalidCredentialsError)
  } else {
    return cy.get('#toaster').invoke('text')
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Assuming that login.getToastError() translates into something like cy.get('selector') then you can do something like this:

For partial text match:

it('Login with invalid password', () => {
  login.enterEmail(testData.username)
  login.enterPassword(testData.invalidPassword)
  login.submit()
  login
    .getToastError()
    .should('be.visible')
    .and('include.text', testData.invalidCredentialsError)
})

For exact text match:

it('Login with invalid password', () => {
  login.enterEmail(testData.username)
  login.enterPassword(testData.invalidPassword)
  login.submit()
  login
    .getToastError()
    .should('be.visible')
    .and('have.text', testData.invalidCredentialsError)
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda