Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!