0
0
Cypresstesting~10 mins

Environment variables for configuration in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access an environment variable in Cypress.

Cypress
const baseUrl = Cypress.env([1]);
Drag options to blanks, or click blank then click option'
Aprocess.env.BASE_URL
BbaseUrl
C"BASE_URL"
Denv.BASE_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes inside Cypress.env()
Trying to access environment variables via process.env in Cypress test code
2fill in blank
medium

Complete the code to set a default value for an environment variable in Cypress test.

Cypress
const apiUrl = Cypress.env([1]) || "https://default.api.com";
Drag options to blanks, or click blank then click option'
AAPI_URL
B"API_URL"
CapiUrl
Dprocess.env.API_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variable name without quotes
Using process.env in Cypress test code
3fill in blank
hard

Fix the error in the code to correctly read an environment variable in Cypress.

Cypress
cy.visit(Cypress.env([1]));
Drag options to blanks, or click blank then click option'
A"BASE_URL"
Bprocess.env.BASE_URL
CbaseUrl
DBASE_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes
Trying to access process.env in Cypress test code
4fill in blank
hard

Fill both blanks to set and get an environment variable in Cypress configuration.

Cypress
Cypress.config([1]: Cypress.env([2]));
Drag options to blanks, or click blank then click option'
A"baseUrl"
B"BASE_URL"
CbaseUrl
DBASE_URL
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes for keys
Mixing uppercase and lowercase incorrectly
5fill in blank
hard

Fill all three blanks to create a test that uses an environment variable for login URL and asserts the page title.

Cypress
describe('Login Test', () => {
  it('visits login page', () => {
    cy.visit(Cypress.env([1]));
    cy.title().should([2], [3]);
  });
});
Drag options to blanks, or click blank then click option'
A"LOGIN_URL"
B"eq"
C"Login Page"
D"loginUrl"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around environment variable name
Using wrong assertion method
Forgetting quotes around expected title