The click command is missing parentheses; it should be click() to execute.
Step 2: Verify other parts
The selector and URL assertion are correct; cy.visit() is valid in Cypress.
Final Answer:
Missing parentheses after click command -> Option B
Quick Check:
Use click() not click [OK]
Hint: Always add () after commands like click() [OK]
Common Mistakes:
Forgetting parentheses on commands
Changing valid selectors unnecessarily
Replacing cy.visit() with non-existent commands
5. 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
A. cy.visit('/')
cy.get('a.profile-link').click
cy.url().should('include', '/profile')
cy.contains('User Profile').should('be.visible')
B. cy.visit('/profile')
cy.get('a.home-link').click()
cy.url().should('include', '/')
cy.contains('Home').should('be.visible')
C. cy.visit('/')
cy.get('a.profile-link').click()
cy.url().should('eq', '/profile')
cy.contains('User Profile').should('not.exist')
D. cy.visit('/')
cy.get('a.profile-link').click()
cy.url().should('include', '/profile')
cy.contains('User Profile').should('be.visible')
Solution
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.
Step 2: Verify page content assertion
It also checks that 'User Profile' text is visible, confirming correct page content after navigation.
Final Answer:
cy.visit('/')
cy.get('a.profile-link').click()
cy.url().should('include', '/profile')
cy.contains('User Profile').should('be.visible') -> Option D
Quick Check:
Visit, click, check URL and content [OK]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.