0
0
Cypresstesting~10 mins

Test configuration per environment 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 load environment variables in Cypress.

Cypress
cy.[1]('baseUrl').should('not.be.undefined')
Drag options to blanks, or click blank then click option'
AsetEnv
BgetEnv
Cenv
Dconfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.getEnv() which does not exist.
Using cy.config() which is for config settings.
2fill in blank
medium

Complete the code to set the base URL for the test environment in Cypress config.

Cypress
module.exports = {
  e2e: {
    baseUrl: '[1]'
  }
}
Drag options to blanks, or click blank then click option'
Ahttp://localhost:3000
Blocalhost
C3000
Dhttp://test-env
Attempts:
3 left
💡 Hint
Common Mistakes
Using only 'localhost' without protocol.
Using only port number without protocol and host.
3fill in blank
hard

Fix the error in the code to correctly read environment variables in a test.

Cypress
const apiUrl = Cypress.[1]('API_URL')
expect(apiUrl).to.exist
Drag options to blanks, or click blank then click option'
AgetConfig
Bconfig
CgetEnv
Denv
Attempts:
3 left
💡 Hint
Common Mistakes
Using Cypress.config() which is for config, not env variables.
Using non-existent methods like getEnv().
4fill in blank
hard

Fill both blanks to set environment variables for different environments in Cypress config.

Cypress
module.exports = {
  e2e: {
    env: {
      [1]: 'https://dev.api.com',
      [2]: 'https://prod.api.com'
    }
  }
}
Drag options to blanks, or click blank then click option'
AdevApiUrl
BprodApiUrl
CbaseUrl
DapiUrl
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for both variables.
Using reserved config keys like baseUrl inside env.
5fill in blank
hard

Fill all three blanks to use environment variables in a test to visit different URLs based on environment.

Cypress
const url = Cypress.env('[1]') || '[2]'

cy.visit(url)

expect(url).to[3]('https://')
Drag options to blanks, or click blank then click option'
AdevApiUrl
Bhttp://localhost:3000
Ccontain
DprodApiUrl
Attempts:
3 left
💡 Hint
Common Mistakes
Using prodApiUrl instead of devApiUrl.
Using 'equal' instead of 'contain' for partial match.
Using an invalid fallback URL.