0
0
Cypresstesting~5 mins

cypress.config.js settings

Choose your learning style9 modes available
Introduction

The cypress.config.js file helps you set up how Cypress runs your tests. It controls things like the base website address and test behavior.

You want to tell Cypress which website to test by default.
You need to change how long Cypress waits for things before giving up.
You want to set up special options like where screenshots or videos are saved.
You want to enable or disable certain features like retries or experimental options.
Syntax
Cypress
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'https://example.com',
    supportFile: 'cypress/support/e2e.js',
    specPattern: 'cypress/e2e/**/*.cy.js',
    setupNodeEvents(on, config) {
      // event listeners here
    },
    retries: 2,
    defaultCommandTimeout: 4000
  },
  video: true,
  screenshotsFolder: 'cypress/screenshots'
})

Use defineConfig to get better editor support and validation.

The e2e section is for end-to-end test settings.

Examples
Sets the base URL for all tests to https://myapp.com.
Cypress
module.exports = defineConfig({
  e2e: {
    baseUrl: 'https://myapp.com'
  }
})
Retries failed tests once and waits 5 seconds for commands by default.
Cypress
module.exports = defineConfig({
  e2e: {
    retries: 1,
    defaultCommandTimeout: 5000
  }
})
Disables video recording and changes the screenshots folder.
Cypress
module.exports = defineConfig({
  video: false,
  screenshotsFolder: 'my-screenshots'
})
Sample Program

This config sets the base URL to Cypress example site, retries failed tests once, waits 3 seconds for commands, and enables video recording.

Cypress
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'https://example.cypress.io',
    retries: 1,
    defaultCommandTimeout: 3000,
    setupNodeEvents(on, config) {
      // no events for now
    }
  },
  video: true
})
OutputSuccess
Important Notes

Always restart Cypress after changing cypress.config.js to apply new settings.

Use relative paths for files and folders inside the config.

Keep your config simple and only add settings you need to avoid confusion.

Summary

cypress.config.js controls how Cypress runs tests.

Set baseUrl, timeouts, retries, and file locations here.

Use defineConfig for better support and clarity.