Bird
0
0

You want to test navigation from the homepage to a user profile page and verify the URL and page content. Which Cypress test code correctly validates routing and content?

hard📝 framework Q15 of 15
Cypress - Navigation and URL
You want to test navigation from the homepage to a user profile page and verify the URL and page content. Which Cypress test code correctly validates routing and content?
Acy.visit('/') cy.get('a.profile-link').click cy.url().should('include', '/profile') cy.contains('User Profile').should('be.visible')
Bcy.visit('/profile') cy.get('a.home-link').click() cy.url().should('include', '/') cy.contains('Home').should('be.visible')
Ccy.visit('/') cy.get('a.profile-link').click() cy.url().should('eq', '/profile') cy.contains('User Profile').should('not.exist')
Dcy.visit('/') cy.get('a.profile-link').click() cy.url().should('include', '/profile') cy.contains('User Profile').should('be.visible')
Step-by-Step Solution
Solution:
  1. Step 1: Check navigation and URL validation

    cy.visit('/') cy.get('a.profile-link').click() cy.url().should('include', '/profile') cy.contains('User Profile').should('be.visible') visits homepage, clicks profile link, then asserts URL includes '/profile' correctly.
  2. Step 2: Verify page content assertion

    It also checks that 'User Profile' text is visible, confirming correct page content after navigation.
  3. Final Answer:

    cy.visit('/') cy.get('a.profile-link').click() cy.url().should('include', '/profile') cy.contains('User Profile').should('be.visible') -> Option D
  4. Quick Check:

    Visit, click, check URL and content [OK]
Quick Trick: Check URL and visible content after click for full validation [OK]
Common Mistakes:
  • Using click without parentheses
  • Checking wrong URL or missing content check
  • Asserting non-existent elements or wrong URLs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes