Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
How to test multiple floating messages with the same content in cypress?

I am fairly new to cypress and practicing its functionalities on Facebook app. I am having an issue on testing these following scenarios:

1.When clicked on First Name, this floating dialog should be visible. 2.Validating the text in the dialog box to be 'What's your name?'. 3.When clicked on Last Name, again a floating box with the same content "What's your name?" should be visible.

Now I am able to test the first two scenario with this.

cy.get('[name="firstname"]').click();//i)-> Click on the firstname
        cy.get('[name="lastname"]').click();//ii)-> Click on the last name    
        cy.get('[name="firstname"]').click(); //iii)-> This will triggers the error message popup for firstname 
        cy.contains('What\'s your name?').should('be.visible').and('contain','What\'s your name?');// Checking the message popup should be displayed and its message is 'What's your name'
        cy.get('[name="lastname"]').click();//v)-> This will trigger the error message popup for lastname
    
        cy.contains('What\'s your name?').should('be.visible').and('contain','What\'s your name?');//vi)-> Checking for that message but not working

But in the third scenario, it is showing the error. I tried to access the element using id but it was showing not found. Error Message Facebook Page

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think cy.contains('What\'s your name?') is catching the message from firstName field which was activated from the initial two commmands but hidden when you navigated to the lastName field (but still remains in the page).

Specify which one you want

cy.get('div:contains(What\'s your name?)').eq(1).should('be.visible')  // .and(contain) not needed

In case that quote in the text distorts the selection you may need to go with cy.get('div:contains(your name?)').eq(1).

Don't use cy.contains('What\'s your name?') it will only ever return the first one it finds.

The Facebook page is not very tester friendly, usually you can request the page elements have some test id's added so you can go directly to then.

Another way to tackle the anonymous popup stuff is just to grab the last thing added to the page, like

cy.get('body')
  .children()
  .last()
  .should('contain', 'What\'s your name?')
  .should('be.visible')
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda