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

140
Visualizações
Cypress: function of click random element and storage its title to verify later

this is my first question of stackoverflow community, I am currently working with Cypress and have created test case that randomly clicks an element from a list. I am trying to also get the text from that same function for my case, i am trying to do;

  • Open main site
  • Select any elements from elements section (randomly)
  • Once details page for the selected elements is opened verify its title equals to the titles selected in previous page
  • The problem is I am unable to return the title properly I can't get the titles to be equal. The code I currently have is:

    context('Select feature of site', () => {
       it('Randomly select element of elements section', () => {
           cy.visit('website url')
           cy.wait(600)
           cy.get('.element_container')
            .children()
            .eq(Math.floor(Math.random() * 44))
            .click({force: true}) 
            .each(($containerSubNewsListWrapper) => {
           cy.get($containerSubNewsListWrapper).click()
            // cy.title().should('eq','') i stucked here
           })
       }) })
       

I click randomly but I'm stuck on syncing the title,i would need to retrieve a title for an item selected randomly and store it somewhere, verify afterwards. I appreciate any ideas

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

0

To save the title in a variable using an alias you can do something like this:

cy.title().as('title1')

Then, When you are inside a different page and want to validate that the title matches the previous title you can do something like:

cy.get("@title1").then((title1) => {
  cy.title().then((title2) => {.   //get the title of the current page
    expect(title1).to.equal(title2)
  })
})
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