Complete the code to access an environment variable in Cypress.
const baseUrl = Cypress.env([1]);In Cypress, environment variables are accessed using Cypress.env() with the variable name as a string.
Complete the code to set a default value for an environment variable in Cypress test.
const apiUrl = Cypress.env([1]) || "https://default.api.com";
Environment variable names must be passed as strings to Cypress.env(). This code sets a default if the variable is not set.
Fix the error in the code to correctly read an environment variable in Cypress.
cy.visit(Cypress.env([1]));The environment variable name must be a string inside Cypress.env(). Without quotes, it causes an error.
Fill both blanks to set and get an environment variable in Cypress configuration.
Cypress.config([1]: Cypress.env([2]));
To set the baseUrl config from an environment variable, use the config key as a string and the env variable name as a string.
Fill all three blanks to create a test that uses an environment variable for login URL and asserts the page title.
describe('Login Test', () => { it('visits login page', () => { cy.visit(Cypress.env([1])); cy.title().should([2], [3]); }); });
The test visits the URL from the environment variable LOGIN_URL. It then asserts the page title equals Login Page using the eq assertion.