0
0
Cypresstesting~15 mins

Test naming conventions in Cypress - Build an Automation Script

Choose your learning style9 modes available
Verify login functionality with proper test naming
Preconditions (1)
Step 1: Enter 'user@example.com' in the email input field
Step 2: Enter 'Password123' in the password input field
Step 3: Click the login button
Step 4: Verify that the URL changes to '/dashboard'
Step 5: Verify that the page contains a welcome message
✅ Expected Result: User is successfully logged in and redirected to the dashboard page with a welcome message displayed
Automation Requirements - Cypress
Assertions Needed:
URL includes '/dashboard'
Page contains welcome message text
Best Practices:
Use descriptive test names that clearly state what is being tested and expected outcome
Use 'describe' and 'it' blocks with meaningful names
Keep test names short but informative
Avoid generic names like 'test1' or 'check login'
Automated Solution
Cypress
describe('Login Functionality', () => {
  it('should log in successfully with valid credentials and redirect to dashboard', () => {
    cy.visit('/login');
    cy.get('#email').type('user@example.com');
    cy.get('#password').type('Password123');
    cy.get('#login-button').click();
    cy.url().should('include', '/dashboard');
    cy.contains('Welcome').should('be.visible');
  });
});

The describe block groups tests related to login functionality.

The it block has a clear, descriptive name explaining what the test does: it logs in with valid credentials and expects a redirect to the dashboard.

Selectors use IDs for clarity and reliability.

Assertions check the URL and presence of a welcome message to confirm successful login.

This naming style helps anyone reading the test understand its purpose immediately.

Common Mistakes - 3 Pitfalls
{'mistake': "Using vague test names like 'test1' or 'login test'", 'why_bad': 'Such names do not explain what the test actually verifies, making maintenance and debugging harder.', 'correct_approach': "Use descriptive names like 'should log in successfully with valid credentials and redirect to dashboard' that clearly state the test purpose."}
Writing very long test names that are hard to read
{'mistake': "Not using 'describe' and 'it' blocks properly", 'why_bad': 'Improper structure makes tests harder to organize and understand.', 'correct_approach': "Use 'describe' to group related tests and 'it' for individual test cases with clear names."}
Bonus Challenge

Now add data-driven testing with 3 different sets of valid login credentials using Cypress 'it.each' or similar approach

Show Hint