Tests Structure | Bondar Academy
Course: Cypress UI Testing with JavaScript
Module: Cypress Hands-On Overview
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore the Cypress test structure and how to effectively organize tests within spec files. Here are the key points covered: Creating a Spec File Create a new spec file in the root of the E2E folder, e.g., firsttest.cy.js . Add a reference to the Cypress library by copying the first line from an existing file, such as todo.cy.js . This enables IntelliSense in Visual Studio Code, allowing you to see available cy commands. Writing Tests Each test starts with the it method, which takes two arguments: Test name (e.g., hello world one ) A callback function using fat arrow syntax to define the test logic. Run tests using npx cypress open to see them recognized in the Cypress runner. Organizing Tests Group tests using the describe method, which allows for nested test suites. Example structure: describe('Test Suite One', () => { it('Test One', () => {}); it('Test Two', () => {}); }); Using Hooks Utilize test hooks like beforeEach and afterEach to perform actions before or after tests. Example of beforeEach to navigate to a homepage: beforeEach(() => { cy.visit('/'); }); Avoid using before or after hooks as they may create dependencies between tests. By following these guidelines, you can effectively organize your tests within Cypress spec files. In the next lesson, we will build on this foundation.