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

244
Visualizações
Using async await in Cypress

I'm very new in Cypress and I'm trying to take a value from an element to use after in the test, but I can't manage to get the value. Someone said that I need to use async await, but it is not working or maybe I'm doing something wrong. Thanks in advance!

it.only('should access Time Worked section and insert same Staff Complement value, but negative as Flexitime',  function () {
        let timeValue = 0;
        cy.get('[data-tag="staff-complement-input"] > div > span').invoke('text').then(text => +text).then(($val) => {
            // $val = 420
            timeValue = $val;
            cy.log(timeValue) //420
        })
        cy.log(timeValue) // 0
        // need timeValue to be 420
 })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use aliases and save the value and use it later.

cy.get('[data-tag="staff-complement-input"] > div > span')
  .invoke("text")
  .then((text) => +text)
  .as("someNum")

cy.get("@someNum").then((someNum) => {
  cy.log(someNum) //420
})

One point to remember is that cypress clears aliases after every test. So the above will only work if you are doing everything under one it() block.

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