Cypress is a JavaScript-native E2E testing framework that runs directly in the browser — no WebDriver protocol, no separate driver process. Tests are fast, reliable, and easy to debug.
Installation
npm install --save-dev cypress
# or
yarn add --dev cypressAdd a script to package.json:
{
"scripts": {
"cypress:open": "cypress open",
"cypress:run": "cypress run"
}
}Run npx cypress open once to generate the default folder structure.
Folder Structure
cypress/
├── e2e/ ← your test files go here
├── fixtures/ ← static test data (JSON)
├── support/
│ ├── commands.js ← custom commands
│ └── e2e.js ← runs before every test file
cypress.config.jsYour First Test
// cypress/e2e/homepage.cy.js
describe('Homepage', () => {
it('loads and shows the heading', () => {
cy.visit('https://example.com')
cy.get('h1').should('contain', 'Example Domain')
})
it('has a working link', () => {
cy.visit('https://example.com')
cy.get('a').first().should('have.attr', 'href')
})
})Run headlessly in CI:
npx cypress run --spec "cypress/e2e/homepage.cy.js"The Cypress Test Runner
Cypress test runner simulation
Ctrl+Enter
HTML
CSS
JS
Preview
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
viewportWidth: 1280,
viewportHeight: 720,
video: false,
screenshotOnRunFailure: true,
},
})With baseUrl set, cy.visit('/login') resolves to http://localhost:3000/login.