Jul 16, 2024
before
, beforeEach
, afterEach
, and after
.life_cycle_hooks.cy.js
.describe
to define a test suite.before
:
before(() => {
cy.log('This lifecycle hook will be executed once before all tests in the spec file');
});
beforeEach
:
beforeEach(() => {
cy.log('This lifecycle hook will be executed before each test case');
});
afterEach
:
afterEach(() => {
cy.log('This lifecycle hook will be executed after each test case');
});
after
:
after(() => {
cy.log('This lifecycle hook will be executed once after all tests in the spec file');
});
it('Test Case 1', () => {
cy.visit('/');
cy.get('input[name=username]').type('admin');
cy.get('input[name=password]').type('password');
cy.get('form').submit();
});
it('Test Case 2', () => {
cy.visit('/');
cy.get('input[name=username]').type('admin');
cy.get('input[name=password]').type('password');
cy.get('form').submit();
});