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

134
Vistas
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 Respuestas
Responde la pregunta

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 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