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

176
Vistas
Skip a global function on Cypress

I have some global variables on my cypress test scenario.

    describe('AutoLogin Test Case',function(){
        beforeEach(function(){
            Cypress.Cookies.preserveOnce('_session_id')
        })
        afterEach(function(){
            cy.get('[id="ajax_working"]',{timeout:6000}).should('not.be.visible')
        })
    
    
        it('input login info',function(){ 
            cy.visit('https://***********.******.com/')
            cy.get('[id^=user_username]')
            .type('ChrisPbacon').should('have.value','ChrisPbacon')
            cy.get('[id^=user_password]')
            .type('welcome123').should('have.value','welcome123')
            cy.contains('Sign In Now').click()
        })
})

After the test case is completed the system is gonna check for the "after each" function and look for "ajax_working"... I need to skip that check ONLY on the shown "it" test, but I still need to run it on the rest of the program. I don't wanna write the aftermath function on each test as it's cumbersome and overall not clean. Anyone got any tips?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure if this will fit your problem, but one of the ways you could achieve this is to wrap afterEach hook in the same context with tests than need it using describe declaration, like this:

beforeEach(function () {
    cy.log("Before each hook");
});

describe('AutoLogin Test Case',function() {

    afterEach(function () {
        cy.log("After each hook");
    });

    it('Some test', function () {
        cy.log("Your first test case")
    });

});

describe('AutoLogin Test Case 2',function() {
    it('Some other test', function() {
        cy.log("Your second test case");
    });
});

Note the output which has your expected behavior, beforeEach hook called in both tests, while afterEach hook is called only on first test:

enter image description here

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