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

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

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 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!