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
Cypress run test on condition

I'm not clear on how to run tests only if an async condition is satisfied: if an element is present on the page.

It'd be something like that, which obviously doesn't work. I can see the alert "enabled", but the nested test "Run proper tests" won't run. What is the right way to do this? Of course, this is simplified, there are a lot of more tests, not just 1.

context("table", () => {

    it("Check availability", () => {
        cy.get("div.table").then($div => {
            if (!Cypress.$(".header[title]", $div).length) {
                alert("not enabled");
            } else {
                alert("enabled");
                it("Run proper tests", () => {...});
            }
        });
    });
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I would make a new instance and use a variable

context("table", () => {

let result

    it("Check availability", () => {
        cy.get("div.table").then($div => {
            if (!Cypress.$(".header[title]", $div).length) {
                alert("not enabled");
                result='fail'
            } 
            else {
                alert("enabled");
            }
     })

     it("Run proper tests", () => {
          if (result === 'fail') {
          console.log('not enabled')
          }
          else {
           Run proper test
               }
     })
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You could try Mocha's pending tests feature via this.skip():

context("table", () => {

    it("Run proper tests", () => {
        cy.get("div.table").then(function($div) {
            if (!Cypress.$(".header[title]", $div).length) {
                this.skip()
            } else {
                // Run proper test
            }
        });
    });
});

This is how a skipped test is displayed in the Cypress runner: enter image description here

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