woocommerce/tests/e2e-tests
Julia Amosova 337b134c10 Implement Puppeteer architecture & add basic test 2019-08-23 11:34:07 +01:00
..
config Implement Puppeteer architecture & add basic test 2019-08-23 11:34:07 +01:00
data Update e2e tests database to WP 5.0.1 and WC 3.5.2 2018-12-19 13:00:55 +00:00
front-end update checkout flow for 3.5.0 2018-12-18 14:23:11 -04:00
specs Implement Puppeteer architecture & add basic test 2019-08-23 11:34:07 +01:00
wp-admin Update e2e test for variations to accomodate new missing price message on variations. 2019-07-14 17:47:30 +02:00
README.md Implement Puppeteer architecture & add basic test 2019-08-23 11:34:07 +01:00
config-setup.js use a more appropriate description for new installation tests 2018-12-18 16:28:49 -04:00

README.md

WooCommerce End to End Tests

Automated end-to-end tests for WooCommerce.

Table of contents

Pre-requisites

Install NodeJS

brew install node #MacOS

Install dependencies

npm install

Configuration

Test Configuration

The tests use environment variables to specify values for the tests.

To login to the site, loginUser() utility function of e2e-test-utils package is being used. The function relies on the following config.js file to specify base URL, Admin user details and Test user details (could be different from Admin. For example, customer):

const WP_ADMIN_USER = {
 	username: 'admin',
 	password: 'password',
 };
 
 const {
 	WP_USERNAME = WP_ADMIN_USER.username,
 	WP_PASSWORD = WP_ADMIN_USER.password,
 	WP_BASE_URL = 'http://localhost:8889',
 } = process.env;
 
 export {
 	WP_ADMIN_USER,
 	WP_USERNAME,
 	WP_PASSWORD,
 	WP_BASE_URL,
 };

As per above, create an Admin user on the site and set its username and password:

  • username: admin
  • password: password

Specify base URL and Test user details using environment variables.

Environment variables

Set environmental variables as shown below. Note that you don't need to add the trailing slash ('/') at the end of the site URL:

  • export WP_BASE_URL={your site URL}
  • export WP_USERNAME={your Test user username}
  • export WP_PASSWORD={your Test user password}

You can unset the variables when you are done:

  • unset WP_BASE_URL
  • unset WP_USERNAME
  • unset WP_PASSWORD

Running tests

How to run tests

To run e2e tests use the following command:

npm run test:e2e

Puppeteer runs headless by default. However, sometimes it's useful to observe the browser while running tests. To do so you can use these environment variables:

PUPPETEER_HEADLESS=false PUPPETEER_SLOWMO=50 npm run test:e2e

SlowMo slows down Puppeteers operations so we can see whats going on in the browser. PUPPETEER_SLOWMO=50 means test actions will be slowed down by 50 milliseconds.

To run an individual test, use the direct path to the spec. For example:

npm run test-e2e ./tests/e2e-tests/specs/activate-woocommerce.test.js

You can also provide the base URL, Test username and Test password like this:

WP_BASE_URL={your site URL} WP_USERNAME={your Test user username} WP_PASSWORD={your Test user password} npm run test:e2e

Writing tests

We use the following tools to write e2e tests:

  • Puppeteer a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol
  • jest-puppeteer provides all required configuration to run tests using Puppeteer
  • expect-puppeteer assertion library for Puppeteer

Tests are kept in tests/e2e-tests/specs folder.

The following packages are being used to write tests:

  • e2e-test-utils - End-To-End (E2E) test utils for WordPress. You can find the full list of utils here.