2020-10-09 13:31:45 +00:00
# WooCommerce Core End to End Test Suite
This package contains the automated end-to-end tests for WooCommerce.
## Table of contents
- [Pre-requisites ](#pre-requisites )
- [Setting up core tests ](#setting-up-core-tests )
- [Test functions ](#test-functions )
- [Activation and setup ](#activation-and-setup )
- [Merchant ](#merchant )
- [Shopper ](#shopper )
- [Contributing a new test ](#contributing-a-new-test )
## Pre-requisites
### Setting up the test environment
2021-11-04 11:58:11 +00:00
Follow [E2E setup instructions ](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/tests/e2e/README.md ).
2020-10-09 13:31:45 +00:00
### Setting up core tests
2021-12-09 20:53:06 +00:00
#### Version 0.2.0 or newer
Version 0.2.0 added a test installer that will populate the `tests/e2e/specs` folder with test scripts for all the current core test suite. It also creates sample configuration files including all the configuration data needed to run the core tests.
- Install the e2e-environment `npm install @woocommerce/e2e-environment --save-dev`
- Run the installer `npx wc-e2e install @woocommerce/e2e-core-tests`
- Merge the sample configuration files:
- `tests/e2e/docker/woocommerce.e2e-core-tests.sh` => `initialize.sh`
- `tests/e2e/config/default-woocommerce.e2e-core-tests.json` => `default.json`
#### Version 0.1.X or other test runner
2020-10-09 13:31:45 +00:00
- Create the folder `tests/e2e/specs` in your repository if it does not exist.
- To add a core test to your test suite, create a new `.test.js` file within `tests/e2e/specs` . Example code to run all the shopper tests:
```js
const { runShopperTests } = require( '@woocommerce/e2e-core-tests' );
runShopperTests();
```
2021-04-12 17:33:00 +00:00
## Retrying/Re-running tests
On a new site, the setup and activation tests prepare the site for the remainder of the tests. To retry/rerun the test suite on a site where setup/onboarding test have already run use the environment variable `E2E_RETEST=1` .
2020-10-09 13:31:45 +00:00
## Test functions
The functions to access the core tests are:
### Activation and setup
- `runSetupOnboardingTests` - Run all setup and onboarding tests
2021-01-20 16:15:46 +00:00
- `runActivationTest` - Merchant can activate WooCommerce
2021-01-19 13:00:59 +00:00
- `runOnboardingFlowTest` - Merchant can complete onboarding flow
- `runTaskListTest` - Merchant can complete onboarding task list
- `runInitialStoreSettingsTest` - Merchant can complete initial settings
2020-10-09 13:31:45 +00:00
### Merchant
- `runMerchantTests` - Run all merchant tests
2021-05-24 15:37:33 +00:00
- `runAddShippingClassesTest` - Merchant can create shipping classes and let shopper test them
2021-03-17 19:40:49 +00:00
- `runAddNewShippingZoneTest` - Merchant can create shipping zones and let shopper test them
2021-01-19 13:00:59 +00:00
- `runAddSimpleProductTest` - Merchant can create a simple product
- `runAddVariableProductTest` - Merchant can create a variable product
2021-03-16 19:00:01 +00:00
- `runCreateCouponTest` - Merchant can create coupon
- `runCreateOrderTest` - Merchant can create order
- `runMerchantOrdersCustomerPaymentPage` - Merchant can visit the customer payment page
- `runMerchantOrderEmailsTest` - Merchant can receive order emails and resend emails by Order Actions
2021-05-24 15:37:33 +00:00
- `runEditOrderTest` - Merchant can edit an order in the dashboard
2021-01-19 13:00:59 +00:00
- `runOrderStatusFilterTest` - Merchant can filter orders by order status
- `runOrderRefundTest` - Merchant can refund an order
- `runOrderApplyCouponTest` - Merchant can apply a coupon to an order
2021-03-17 19:40:49 +00:00
- `runOrderSearchingTest` - Merchant can search for order via different terms
2021-01-20 23:19:07 +00:00
- `runProductEditDetailsTest` - Merchant can edit an existing product
- `runProductSearchTest` - Merchant can search for a product and view it
2021-03-16 19:00:01 +00:00
- `runProductSettingsTest` - Merchant can update product settings
- `runTaxSettingsTest` - Merchant can update tax settings
- `runUpdateGeneralSettingsTest` - Merchant can update general settings
2021-03-03 16:57:11 +00:00
- `runMerchantOrderEmailsTest` - Merchant can receive order emails and resend emails by Order Actions
2021-03-25 09:21:32 +00:00
- `runAnalyticsPageLoadsTest` - Merchant can load and see all pages in Analytics
2021-03-18 16:23:44 +00:00
- `runImportProductsTest` - Merchant can import products via CSV file
2021-05-24 15:37:33 +00:00
- `runInitiateWccomConnectionTest` - Merchant can initiate connection to WooCommerce.com
2021-11-26 16:06:00 +00:00
- `runAdminPageLoadTests` - Merchant can load pages from the WP Admin sidebar
2020-10-09 13:31:45 +00:00
### Shopper
- `runShopperTests` - Run all shopper tests
2021-02-04 19:45:57 +00:00
- `runCartApplyCouponsTest` - Shopper can use coupons on cart
2021-01-20 16:15:46 +00:00
- `runCartPageTest` - Shopper can view and update cart
2021-02-04 19:45:57 +00:00
- `runCheckoutApplyCouponsTest` - Shopper can use coupons on checkout
2021-01-19 13:00:59 +00:00
- `runCheckoutPageTest` - Shopper can complete checkout
- `runMyAccountPageTest` - Shopper can access my account page
2021-03-16 19:00:01 +00:00
- `runMyAccountPayOrderTest` - Shopper can pay for their order in My Account
2021-02-04 13:44:23 +00:00
- `runProductBrowseSearchSortTest` - Shopper can browse, search & sort products
2021-03-16 19:00:01 +00:00
- `runSingleProductPageTest` - Shopper can view single product page in many variations (simple, variable, grouped)
2021-03-03 13:10:20 +00:00
- `runVariableProductUpdateTest` - Shopper can view and update variations on a variable product
2021-03-25 12:17:42 +00:00
- `runCheckoutCreateAccountTest` - Shopper can create an account during checkout
2021-04-01 09:10:43 +00:00
- `runCheckoutLoginAccountTest` - Shopper can login to an account during checkout
2021-04-01 13:38:53 +00:00
- `runMyAccountCreateAccountTest` - Shopper can create an account via my account page
2021-04-07 15:52:58 +00:00
- `runCartCalculateShippingTest` - Shopper can calculate shipping in the cart
2021-04-05 13:53:49 +00:00
- `runCartRedirectionTest` - Shopper is redirected to the cart page after adding to cart
2021-04-15 11:28:25 +00:00
- `runOrderEmailReceivingTest` - Shopper can receive an email for his order
2022-06-03 16:01:04 +00:00
- `runCartAndCheckoutConsistentShippingTest` - Shopper gets consistent shipping information on cart and checkout pages
2020-10-09 13:31:45 +00:00
2021-03-16 19:00:01 +00:00
### REST API
- `runApiTests` - Run all API tests
- `runExternalProductAPITest` - Can create, read, and delete an external product
- `runGroupedProductAPITest` - Can create, read, and delete a grouped product
- `runVariableProductAPITest` - Can create, read, and delete a variable product and its variations
- `runCouponApiTest` - Can create, read, and delete a coupon
2021-05-24 15:37:33 +00:00
- `runOrderApiTest` - Can create, read, and delete an order
2021-03-16 19:00:01 +00:00
2020-10-09 13:31:45 +00:00
## Contributing a new test
2021-12-10 15:22:08 +00:00
- In your branch create a new `example-test-name.test.js` under the appropriate folder in the [`specs` ](specs ) directory.
2020-10-09 13:31:45 +00:00
- Jest does not allow its global functions to be accessed outside the jest environment. To allow the test code to be published in a package import any jest global functions used in your test
```js
const {
it,
describe,
beforeAll,
} = require( '@jest/globals' );
```
- Wrap your test in a function and export it
```js
const runExampleTestName = () => {
describe('Example test', () => {
beforeAll(async () => {
// ...
});
it('do some example action', async () => {
// ...
});
// ...
});
});
module.exports = runExampleTestName;
```
2021-12-10 15:22:08 +00:00
- Add your test to [`specs/index.js` ](specs/index.js )
2020-10-09 13:31:45 +00:00
```js
const runExampleTestName = require( './grouping/example-test-name.test' );
// ...
module.exports = {
// ...
runExampleTestName,
}
```