Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Introduction
Why use Cypress?
Cypress allows us to write the following tests, while giving developers access to its interactive GUI
End-to-end tests
Component tests
Integration tests
Unit tests
Grab a coffee while you go through the features of Cypress.
Setup and Installation
Installation Steps
Expand | ||
---|---|---|
| ||
|
Expand | ||
---|---|---|
| ||
|
Expand | ||
---|---|---|
| ||
|
Expand | ||
---|---|---|
| ||
|
Expand | ||
---|---|---|
| ||
1. Click on Specs to see all the tests present |
Dev Tests
While on development environment, check if you have the following file setup in the root folder of your local application (refer to the below image)
...
Common config changes
Put such changes like the viewport height/width settings, etc. directly in the defineConfig
object.
E2E testing config changes
Put changes specific to E2E testing the e2e
object. Following are the current e2e
configs:
Code Block | ||
---|---|---|
| ||
e2e: {
baseUrl: 'http://localhost:3000', // base url for e2e testing
excludeSpecPattern: '**/examples/*', // used to exclude tests whose names are filtered by the regex
screenshotOnRunFailure: false, // if true a screenshot folder will be included with all the screen snippets when your tests fail
}, |
Component testing config changes
Put changes specific to E2E testing the e2e
object. Following are the current e2e
configs:
Code Block | ||
---|---|---|
| ||
component: {
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
},
screenshotOnRunFailure: false,
// Defines environment variables for the component tests
env: {
REACT_APP_MAPBOX_API_KEY: 'pk.eyJ1IjoibWlrYWhwaW5lZ2FyIiwiYSI6ImNseHZ2NndjZDJrejMycXB4dWtlamo2eWYifQ.29yeP8CgZpO98jyzxYxU4Q',
},
}, |
Info |
---|
For customizing the configuration refer the following: |
Writing Tests
Testing Structure
Use the following structure for your test (spec) files:
Describe Blocks: Group related tests.
It Blocks: Define individual test cases.
Assertions: Validate expected outcomes.