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

627
Visualizações
How to assert today's date or older in Cypress

I am trying to write a function in Cypress, where it loops through all the columns for my start date (#EventStart) and makes sure that the start dates are today's current date or older. So for instance, I need this test to make sure that it is confirming that all the dates listed are either today's date (April 4) or earlier (April 3, 2, 1, etc, etc). So far I can get it to confirm today's date, but how can I add to the function so that it also looks for the days prior to today? Also, the way it is written, it is getting me GMT Time, how can I get it to display CST?

EDIT: This is how the date displays: April 4, 2022, 1:00pm

  public assertOldDate () {
    cy.get("#EventStart).each((el) => {
     let oldDate = new Date();
      oldDate.setDate(oldDate.getDate())
      cy.get("el").should("equal", oldDate);
    }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using dayjs to parse the element text,

import dayjs from 'dayjs'

const today = dayjs()

cy.get('[id*="EventStart"]')
  .each($eventStart => {

    const dateText = $eventStart.text()

    Cypress.log({message: `Testing ${dateText}`})               // log as per web page
    const formatted = dateText.split(', ').slice(0,2).join(' ') // remove commas & time 
    const date = dayjs(formatted, 'MMMM DD YYYY')               // parse the text

    expect(date <= today).to.eq(true)
  })

Note, changed id selector to [id*="EventStart"] as id's are expected to bu unique. Using #EventStart seems to block the iteration.

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