Verify navigation using baseUrl configuration in Cypress
Preconditions (2)
✅ Expected Result: The test navigates to 'https://example.com/' using the baseUrl and confirms the main content is visible
describe('Base URL configuration test', () => { it('should navigate to baseUrl and verify main content', () => { cy.visit('/'); cy.url().should('eq', 'https://example.com/'); cy.get('#main-content').should('be.visible'); }); });
This test uses cy.visit('/') which automatically prepends the baseUrl set in cypress.config.js. We then check the full URL with cy.url() to confirm navigation succeeded. Finally, we verify the main content is visible by selecting the element with id='main-content' and asserting it is visible. This approach ensures the baseUrl configuration is correctly used and the page loads as expected.
Now add tests to verify navigation to '/about' and '/contact' pages using baseUrl
baseUrl in Cypress configuration?baseUrl is used to set the main website address once in Cypress config.cy.visit()baseUrl is set, you can use relative paths in cy.visit() instead of full URLs.cy.visit() to simplify test code. -> Option CbaseUrl in cypress.config.js?module.exports = {}.baseUrl (camelCase) and assigned with colon, not equals.baseUrl is set to https://shop.com, what URL will Cypress visit with cy.visit('/cart')?baseUrl is set, relative paths in cy.visit() append to it./cart to https://shop.com results in https://shop.com/cart.baseUrl to https://app.test but cy.visit('login') fails with a 404 error. What is the likely cause?cy.visit() path causes wrong URL. -> Option Bhttps://dev.site and https://prod.site. How can you configure Cypress to switch baseUrl easily?baseUrl in cypress.config.js using environment variables to switch easily.baseUrl dynamically in cypress.config.js. -> Option APass the test and this pattern moves unknown