Complete the code to load environment variables in Cypress.
cy.[1]('baseUrl').should('not.be.undefined')
The cy.env() command accesses environment variables in Cypress.
Complete the code to set the base URL for the test environment in Cypress config.
module.exports = {
e2e: {
baseUrl: '[1]'
}
}The baseUrl must be a full URL including protocol and port, like http://localhost:3000.
Fix the error in the code to correctly read environment variables in a test.
const apiUrl = Cypress.[1]('API_URL') expect(apiUrl).to.exist
The correct method to read environment variables is Cypress.env().
Fill both blanks to set environment variables for different environments in Cypress config.
module.exports = {
e2e: {
env: {
[1]: 'https://dev.api.com',
[2]: 'https://prod.api.com'
}
}
}Environment variables can be named freely; here devApiUrl and prodApiUrl distinguish dev and prod URLs.
Fill all three blanks to use environment variables in a test to visit different URLs based on environment.
const url = Cypress.env('[1]') || '[2]' cy.visit(url) expect(url).to[3]('https://')
The test tries to get devApiUrl environment variable or falls back to localhost. The assertion checks the URL contains 'https://'.