Test Overview
This test demonstrates how using external test data in Cypress improves maintainability by separating test logic from data. It verifies that the login form accepts valid credentials loaded from an external JSON file.
This test demonstrates how using external test data in Cypress improves maintainability by separating test logic from data. It verifies that the login form accepts valid credentials loaded from an external JSON file.
import { describe, it, beforeEach } from 'cypress'; describe('Login form with external test data', () => { let credentials; beforeEach(() => { cy.fixture('loginData.json').then((data) => { credentials = data; }); cy.visit('/login'); }); it('logs in successfully with valid credentials', () => { cy.get('input[name="username"]').type(credentials.username); cy.get('input[name="password"]').type(credentials.password); cy.get('button[type="submit"]').click(); cy.url().should('include', '/dashboard'); cy.get('h1').should('contain.text', 'Welcome'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Load external test data from fixture file 'loginData.json' | Test data object with username and password is loaded into variable | - | PASS |
| 2 | Open browser and navigate to '/login' page | Login page is displayed with username and password fields and submit button | - | PASS |
| 3 | Find username input field and type username from external data | Username field contains the typed username | - | PASS |
| 4 | Find password input field and type password from external data | Password field contains the typed password | - | PASS |
| 5 | Find and click the submit button | Form is submitted, page starts navigation | - | PASS |
| 6 | Verify URL includes '/dashboard' after login | Browser URL is '/dashboard' | URL contains '/dashboard' | PASS |
| 7 | Verify page header contains text 'Welcome' | Page shows header with text 'Welcome' | Header text includes 'Welcome' | PASS |