Complete the code to set the base URL in Cypress configuration.
cy.visit('[1]/login')
The cy.visit() command requires a full URL or a path relative to the base URL. Here, we provide the full URL to visit the login page.
Complete the code to set the base URL in the Cypress config file (cypress.config.js).
export default defineConfig({
e2e: {
[1]: 'http://localhost:3000'
}
})The baseUrl property in Cypress config sets the root URL for all tests, so you can use relative paths in cy.visit().
Fix the error in the Cypress test to use the base URL correctly.
cy.visit('[1]/dashboard')
When baseUrl is set in Cypress config, use relative paths like /dashboard in cy.visit() to avoid repeating the full URL.
Fill both blanks to correctly configure baseUrl and use it in a test.
export default defineConfig({
e2e: {
[1]: 'http://example.com'
}
})
// In test file
cy.visit([2])Set baseUrl in config and use a relative path like '/home' in cy.visit() to visit the page.
Fill all three blanks to configure baseUrl, write a test visiting a page, and assert the URL.
export default defineConfig({
e2e: {
[1]: 'http://myapp.test'
}
})
describe('Home page test', () => {
it('should load home page', () => {
cy.visit([2])
cy.url().should('include', [3])
})
})Set baseUrl to the app URL, visit the root path '/', and check the URL includes '/' to confirm the home page loaded.