0
0
Cypresstesting~20 mins

cy.visit() for page navigation in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Page Navigator Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the result of this cy.visit() command?
Consider this Cypress test code snippet:
cy.visit('/dashboard')

Assuming the baseUrl is set to 'https://example.com', what URL will Cypress navigate to?
Cypress
cy.visit('/dashboard')
Ahttps://example.com
Bhttps://example.com/dashboard
Chttps://example.com//dashboard
Dhttps://dashboard
Attempts:
2 left
💡 Hint
The path in cy.visit() appends to the baseUrl without doubling slashes.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the page loaded after cy.visit()?
After running cy.visit('/login'), which assertion correctly checks that the URL contains '/login'?
Cypress
cy.visit('/login')
Acy.url().should('include', '/login')
Bcy.url().should('eq', '/login')
Ccy.location('pathname').should('contain', 'login')
Dcy.location('href').should('include', 'https://login')
Attempts:
2 left
💡 Hint
Use cy.url() to get the full URL and check if it contains the path.
🔧 Debug
advanced
2:00remaining
Why does this cy.visit() command fail with a 404 error?
Given this code:
cy.visit('dashboard')

The test fails with a 404 error. Why?
Cypress
cy.visit('dashboard')
AMissing leading slash causes Cypress to request 'https://example.comdashboard' which is invalid
Bcy.visit() requires a full URL, not a relative path
CThe baseUrl is not set, so Cypress cannot resolve 'dashboard'
DThe server is down, causing 404 error
Attempts:
2 left
💡 Hint
Check how relative paths without leading slash are resolved.
🧠 Conceptual
advanced
1:30remaining
What happens if cy.visit() is called with an absolute URL different from baseUrl?
If baseUrl is set to 'https://example.com' and the test runs cy.visit('https://other.com/page'), what will Cypress do?
Cypress
cy.visit('https://other.com/page')
ACypress appends '/page' to baseUrl ignoring the domain
BCypress throws an error because URL is outside baseUrl
CCypress navigates to 'https://example.com/https://other.com/page'
DCypress navigates to 'https://other.com/page' ignoring baseUrl
Attempts:
2 left
💡 Hint
Absolute URLs override baseUrl in cy.visit().
framework
expert
2:30remaining
In Cypress, how can you wait for a page to fully load after cy.visit() before running assertions?
Which approach ensures the page is fully loaded before assertions after cy.visit('/home')?
Cypress
cy.visit('/home')
AUse cy.visit('/home').should('have.property', 'readyState', 'complete')
BUse cy.visit('/home').wait(5000) to wait 5 seconds
CUse cy.visit('/home').then(() => cy.get('body')) to wait for body element
DUse cy.visit('/home').its('document.readyState').should('eq', 'complete')
Attempts:
2 left
💡 Hint
Waiting for a visible element is better than fixed delays or document properties.