Verify Cypress can test a modern web application login flow
Preconditions (2)
✅ Expected Result: User is successfully logged in and redirected to the dashboard page with a welcome message
describe('Modern Web App Login Flow', () => { beforeEach(() => { cy.visit('http://localhost:3000') }) it('logs in successfully and shows dashboard', () => { cy.get('[data-cy=username-input]').type('testuser') cy.get('[data-cy=password-input]').type('Test@1234') cy.get('[data-cy=login-button]').click() // Wait for dashboard to load by checking URL cy.url().should('include', '/dashboard') // Verify welcome message cy.contains('Welcome, testuser').should('be.visible') }) })
This Cypress test suite automates the login flow of a modern web application.
beforeEach() ensures the homepage is loaded before each test.
Selectors use data-cy attributes for stable and clear targeting.
We type the username and password, then click the login button.
We assert the URL contains /dashboard to confirm navigation.
Finally, we check the welcome message is visible and contains the username.
This approach uses Cypress best practices like explicit assertions and clear selectors.
Now add data-driven testing to run the login test with 3 different username and password combinations
it() to define individual test cases inside describe() blocks.it() is the function to start a test case. describe() groups tests, but does not start a test itself.cy.visit('https://example.com')
cy.get('button').click()
cy.url().should('include', '/dashboard')cy.visit() opens the page, cy.get('button').click() clicks the button, and cy.url().should('include', '/dashboard') asserts the URL includes '/dashboard'.describe('Login test', () => {
it('logs in user', () => {
cy.visit('https://app.com')
cy.get('#username').type('user1')
cy.get('#password').type('pass123')
cy.get('button.submit').click
cy.url().should('include', '/home')
})
})cy.get('button.submit').click misses parentheses, so the click method is not called.Pass the test and this pattern moves unknown