-
Notifications
You must be signed in to change notification settings - Fork 23
Home
WP Cypress is in active development, the API may be unstable until
v1.0. Where possible, we will try to maintain backwards compatibility. This documentation is relevant for versions > 0.8.0.
WP Cypress is an npm package that is designed to be installed on a per project basis. Please ensure your machine has the following requirements installed.
- Node [version:
>=12.22.0] - Yarn or npm
- Docker
- Install cypress
yarn add cypress --dev- Initialize cypress
yarn run cypress open- Install WP Cypress
yarn add @bigbite/wp-cypress --dev
- Add the support file to
/cypress/support/index.js
import '@bigbite/wp-cypress/lib/cypress-support';- Add the plugin to
/cypress/plugin/index.js.
const wpCypressPlugin = require('@bigbite/wp-cypress/lib/cypress-plugin');
module.exports = async (on, config) => {
return wpCypressPlugin(on, config);
}-
Update
/cypress.jsonwith your configuration. -
Start WP Cypress
yarn run wp-cypress startConfiguration options are added to the cypress configuration in cypress.json under the wp key. See the configuration schema for a full reference of available configuration.
{
"wp": {
"version": ["5.5"],
"plugins": ["./path/to/plugin", "./another/path/to/plugin"],
"themes": ["./path/to/theme"]
}
}{
"wp": {
"version": ["5.5"],
"plugins": ["./path/to/plugin", "./another/path/to/plugin"],
"themes": ["./path/to/theme"],
"muPlugins": {
"vip": true
}
}
}{
"wp": {
"version": ["5.5"],
"plugins": ["./path/to/plugin", "./another/path/to/plugin"],
"themes": ["./path/to/theme"],
"muPlugins": {
"path": "./path/to/mu-plugins "
}
}
}{
"wp": {
"version": ["5.5"],
"plugins": ["./path/to/plugin", "./another/path/to/plugin"],
"themes": ["./path/to/theme"],
"muPlugins": {
"path": "./path/to/client-mu-plugins",
"vip": true
}
}
}{
"wp": {
"version": ["5.5"],
"wpContent": {
"path": "./wp-content",
"activeTheme": "twentynineteen",
"activePlugins": ["my-plugin", "askimet"]
},
}
}{
"wp": {
"version": ["5.5"],
"wpContent": {
"path": "./wp-content",
"activeTheme": "twentynineteen",
"activePlugins": ["my-plugin", "askimet"]
},
"muPlugins": {
"vip": true
},
"configFile": "./wp-content/vip-config/vip-config.php",
}
}Once installed, WP Cypress is executable from ./node_modules/.bin. These commands are now available to run in your project root directory:
| Name | Description | Example | Flags |
|---|---|---|---|
| start | Start a test environment | yarn run wp-cypress start |
--no-volumes |
| stop | Stop the current test environment | yarn run wp-cypress stop |
|
| wp | Execute the WordPress CLI in the running container | yarn run wp-cypress wp "cli version" |
By default, WP Cypress will run on port 80 and be available to access at http://localhost unless a custom port number is specified in the configuration options or you are using a multisite with custom domains and subdomains. In this case you should specify the baseUrl for cypress.
Start a test environment by running yarn run wp-cypress start in your project root directory. This may take a while as it builds and starts a new docker container - however, subsequent builds will be quicker.
Note: If you make a change to the configuration, you will need to re-run wp-cypress start and restart cypress for the changes to take effect.
Try running yarn run wp-cypress --help or please refer to Troubleshooting for common issues.
-
Start writing tests! If you're new to Cypress, the Cypress documentation is a great place to start learning about how to write tests in Cypress.
-
Learn more about how to use wp-cypress: