Why test structure organizes assertions in Cypress - Automation Benefits in Action
describe('Login Page Test', () => { it('should verify login page elements and perform successful login', () => { cy.visit('https://example.com/login'); // Verify input fields and button are visible and enabled cy.get('[data-cy=email-input]') .should('be.visible') .and('be.enabled'); cy.get('[data-cy=password-input]') .should('be.visible') .and('be.enabled'); cy.get('[data-cy=login-button]') .should('be.visible') .and('be.enabled'); // Enter credentials cy.get('[data-cy=email-input]').type('user@example.com'); cy.get('[data-cy=password-input]').type('Password123!'); // Click login cy.get('[data-cy=login-button]').click(); // Verify URL changed to dashboard cy.url().should('eq', 'https://example.com/dashboard'); // Verify welcome message on dashboard cy.get('[data-cy=dashboard-heading]') .should('be.visible') .and('contain.text', 'Welcome, User!'); }); });
This test script uses Cypress to automate the manual test case steps.
First, it visits the login page URL.
Then it groups assertions to check that the email input, password input, and login button are all visible and enabled before interacting with them. Grouping these assertions helps keep the test organized and clear.
Next, it types the provided credentials into the input fields and clicks the login button.
After the login action, it asserts that the URL changes to the dashboard page, confirming navigation success.
Finally, it verifies that the dashboard heading contains the expected welcome text.
Selectors use data-cy attributes for stability and clarity.
This structure organizes assertions logically: first verifying page readiness, then performing actions, then verifying results. This approach makes the test easy to read, maintain, and debug.
Now add data-driven testing with 3 different sets of login credentials (valid and invalid) to verify login success and failure messages.