Verify URL after login
Preconditions (2)
✅ Expected Result: The URL should include '/dashboard' after successful login
describe('Login Page URL Test', () => { it('should navigate to dashboard after login', () => { cy.visit('/login'); cy.get('#email').type('user@example.com'); cy.get('#password').type('Password123!'); cy.get('#loginBtn').click(); cy.url().should('include', '/dashboard'); }); });
This test starts by visiting the login page using cy.visit('/login').
It then types the email and password into their respective input fields using cy.get() with id selectors for reliability.
After clicking the login button, the test waits for the page to navigate by chaining the commands.
Finally, it asserts that the URL includes /dashboard using cy.url().should('include', '/dashboard'), which confirms successful navigation.
This approach avoids arbitrary waits and uses Cypress's built-in retry and wait mechanisms for stability.
Now add data-driven testing with 3 different sets of valid user credentials and verify the URL after login for each.
cy.url().should('include', '/dashboard') check in a Cypress test?cy.visit('/login')
cy.url().should('match', /\/login$/)cy.url().should('equals', 'https://example.com/home')Pass the test and this pattern moves unknown