2021-11-04 11:25:52 +00:00
# WooCommerce End to End Test Utilities
2020-04-21 11:44:55 +00:00
2020-07-10 22:12:21 +00:00
This package contains utilities to simplify writing e2e tests specific to WooCommmerce.
2020-04-21 11:44:55 +00:00
## Installation
```bash
npm install @woocommerce/e2e -utils --save
```
## Usage
Example:
~~~js
import {
2021-01-19 13:00:59 +00:00
shopper,
merchant,
createSimpleProduct
2020-04-21 11:44:55 +00:00
} from '@woocommerce/e2e-utils';
describe( 'Cart page', () => {
beforeAll( async () => {
await createSimpleProduct();
} );
it( 'should display no item in the cart', async () => {
2021-01-19 13:00:59 +00:00
await shopper.goToCart();
2020-04-21 11:44:55 +00:00
await expect( page ).toMatchElement( '.cart-empty', { text: 'Your cart is currently empty.' } );
} );
} );
2020-10-16 19:25:23 +00:00
~~~
2021-04-12 17:33:00 +00:00
### Retries
This package provides support for enabling retries in tests:
- In the test environment set `E2E_RETEST=1` .
- To add conditional logic to your tests use the boolean constant `IS_RETEST_MODE` .
### Available constants
#### Dashboard
- `WP_ADMIN_LOGIN` - WordPress login
- `WP_ADMIN_DASHBOARD` - WordPress dashboard
2021-06-15 22:28:10 +00:00
- `WP_ADMIN_WP_UPDATES` - WordPress updates
2021-04-12 17:33:00 +00:00
- `WP_ADMIN_PLUGINS` - Plugin list
2021-11-04 11:25:52 +00:00
- `WP_ADMIN_PERMALINK_SETTINGS` - Permalink settings
2021-04-12 17:33:00 +00:00
- `WP_ADMIN_ALL_USERS_VIEW` - WordPress user list
- `WP_ADMIN_POST_TYPE` - Post listing
- `WP_ADMIN_NEW_POST_TYPE` - New post
- `WP_ADMIN_ALL_COUPONS_VIEW` - Coupons list
- `WP_ADMIN_NEW_COUPON` - New coupon
- `WP_ADMIN_ALL_ORDERS_VIEW` - Orders list
- `WP_ADMIN_NEW_ORDER` - New Order
- `WP_ADMIN_ALL_PRODUCTS_VIEW` - Products list
- `WP_ADMIN_NEW_PRODUCT` - New product
- `WP_ADMIN_IMPORT_PRODUCTS` - Import products
- `WP_ADMIN_PLUGIN_PAGE` - Plugin settings page root
- `WP_ADMIN_WC_HOME` - WooCommerce home screen
- `WP_ADMIN_SETUP_WIZARD` - WooCommerce setup/onboarding wizard
- `WP_ADMIN_ANALYTICS_PAGES` - WooCommerce analytics page root
- `WP_ADMIN_WC_SETTINGS` - WooCommerce settings page root
- `WP_ADMIN_NEW_SHIPPING_ZONE` - WooCommerce new shipping zone
2021-04-22 10:42:50 +00:00
- `WP_ADMIN_WC_EXTENSIONS` - WooCommerce extensions page
2021-07-15 20:39:32 +00:00
- `WP_ADMIN_PLUGIN_INSTALL` - WordPress plugin install page
2021-04-12 17:33:00 +00:00
#### Front end
- `SHOP_PAGE` - Shop page
2021-11-04 11:25:52 +00:00
- `SHOP_PRODUCT_PAGE` - Single product page
2021-04-12 17:33:00 +00:00
- `SHOP_CART_PAGE` - Cart page
- `SHOP_CHECKOUT_PAGE` - Checkout page
- `SHOP_MY_ACCOUNT_PAGE` - Customer account page
- `MY_ACCOUNT_ORDERS` - Customer orders
- `MY_ACCOUNT_DOWNLOADS` - Customer downloads
- `MY_ACCOUNT_ADDRESSES` - Customer addresses
- `MY_ACCOUNT_ACCOUNT_DETAILS` - Customer account details
2021-09-10 18:56:16 +00:00
## Test Functions
2020-10-16 19:25:23 +00:00
2021-01-19 13:00:59 +00:00
### Merchant `merchant`
2020-10-16 19:25:23 +00:00
2020-12-11 04:27:04 +00:00
| Function | Parameters | Description |
|----------|-------------|------------|
2022-02-28 07:24:33 +00:00
| `addDownloadableProductPermission` | `productName` | Add a downloadable permission for product in order |
2021-12-22 18:54:04 +00:00
| `collapseAdminMenu` | `collapse` | Collapse or expand the WP admin menu |
| `dismissOnboardingWizard` | | Dismiss the onboarding wizard if present |
2021-01-19 13:00:59 +00:00
| `goToOrder` | `orderId` | Go to view a single order |
2021-01-20 23:19:07 +00:00
| `goToProduct` | `productId` | Go to view a single product |
2020-12-11 04:27:04 +00:00
| `login` | | Log in as merchant |
| `logout` | | Log out of merchant account |
| `openAllOrdersView` | | Go to the orders listing |
2021-01-20 23:19:07 +00:00
| `openAllProductsView` | | Go to the products listing |
2020-12-11 04:27:04 +00:00
| `openDashboard` | | Go to the WordPress dashboard |
| `openNewCoupon` | | Go to the new coupon editor |
| `openNewOrder` | | Go to the new order editor |
| `openNewProduct` | | Go to the new product editor |
| `openPermalinkSettings` | | Go to Settings -> Permalinks |
| `openPlugins` | | Go to the Plugins screen |
| `openSettings` | | Go to WooCommerce -> Settings |
| `runSetupWizard` | | Open the onboarding profiler |
| `updateOrderStatus` | `orderId, status` | Update the status of an order |
2021-03-03 16:57:11 +00:00
| `openEmailLog` | | Open the WP Mail Log page |
2021-03-25 09:21:32 +00:00
| `openAnalyticsPage` | | Open any Analytics page |
2021-03-25 12:17:42 +00:00
| `openAllUsersView` | | Open the All Users page |
2021-03-18 16:23:44 +00:00
| `openImportProducts` | | Open the Import Products page |
2021-04-22 10:42:50 +00:00
| `openExtensions` | | Go to WooCommerce -> Extensions |
2021-06-15 22:28:10 +00:00
| `openWordPressUpdatesPage` | | Go to Dashboard -> Updates |
2022-02-28 07:24:33 +00:00
| `revokeDownloadableProductPermission` | `productName` | Remove a downloadable product permission from order |
2021-11-04 11:25:52 +00:00
| `installAllUpdates` | | Install all pending updates on Dashboard -> Updates|
2022-02-28 07:24:33 +00:00
| `updateDownloadableProductPermission` | `productName, expirationDate, downloadsRemaining` | Update the attributes of a downloadable product permission in order |
2021-11-04 11:25:52 +00:00
| `updateWordPress` | | Install pending WordPress updates on Dashboard -> Updates|
| `updatePlugins` | | Install all pending plugin updates on Dashboard -> Updates|
| `updateThemes` | | Install all pending theme updates on Dashboard -> Updates|
2022-02-28 07:24:33 +00:00
| `verifyCannotDownloadFromBecause` | `page, reason` | Verify that cannot download a product from `page` because of `reason` |
| `verifyDownloadableProductPermission` | `productName, expirationDate, downloadsRemaining` | Verify the attributes of a downloadable product permission in order |
2021-08-02 17:11:49 +00:00
| `runDatabaseUpdate` || Runs the database update if needed |
2022-02-28 07:24:33 +00:00
| `openDownloadLink` | | Open the download link of a product |
2020-10-16 19:25:23 +00:00
2021-01-19 13:00:59 +00:00
### Shopper `shopper`
2020-10-16 19:25:23 +00:00
| Function | Parameters | Description |
|----------|------------|-------------|
| `addToCart` | | Add an item to the cart from a single product page |
2021-09-27 16:22:20 +00:00
| `addToCartFromShopPage` | `productIdOrTitle` | Add an item to the cart from the shop page |
2020-10-16 19:25:23 +00:00
| `fillBillingDetails` | `customerBillingDetails` | Fill billing fields in checkout form using configured address |
| `fillShippingDetails` | `customerShippingDetails` | Fill shipping fields in checkout form using configured address |
| `goToAddresses` | | Go to My Account -> Address Details |
| `goToAccountDetails` | | Go to My Account -> Details |
| `goToCart` | | Go to the cart page |
| `goToCheckout` | | Go to the checkout page |
| `goToDownloads` | | Go to My Account -> Downloads |
2021-01-19 13:00:59 +00:00
| `goToMyAccount` | | Go to the My Account page |
| `goToOrders` | | Go to My Account -> Orders |
| `goToProduct` | `productId` | Go to a single product in the shop |
| `goToShop` | | Go to the shop page |
2020-10-16 19:25:23 +00:00
| `login` | | Log in as the shopper |
2021-11-23 13:28:17 +00:00
| `logout` | | Log out of the shopper account |
2020-10-16 19:25:23 +00:00
| `placeOrder` | | Place an order from the checkout page |
| `productIsInCheckout` | `productTitle, quantity, total, cartSubtotal` | Verify product is in cart on checkout page |
2021-09-27 16:22:20 +00:00
| `removeFromCart` | `productIdOrTitle` | Remove a product from the cart on the cart page |
2020-10-16 19:25:23 +00:00
| `setCartQuantity` | `productTitle, quantityValue` | Change the quantity of a product on the cart page |
2021-03-30 22:11:50 +00:00
| `searchForProduct` | | Searching for a product name and landing on its detail page |
2021-08-02 17:11:49 +00:00
| `emptyCart` | | Removes any products and coupons that are in the cart |
2020-10-16 19:25:23 +00:00
2021-04-12 17:33:00 +00:00
### REST API `withRestApi`
2021-11-04 11:25:52 +00:00
Please note: if you're using a non-SSL environment (such as a Docker container from [`wc-e2e` ](https://www.npmjs.com/package/@woocommerce/e2e-environment )) you will need to use Basic Auth in order to authenticate with the API and use the `withRestApi` methods listed below. To do so, you will need to install the [the Basic Auth plugin ](https://github.com/WP-API/Basic-Auth ). One way this can be accomplished is by adding `wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate` to your `initialize.sh` script.
2021-11-04 11:25:52 +00:00
2021-04-12 17:33:00 +00:00
| Function | Parameters | Description |
|----------|------------|-------------|
2021-11-15 16:59:28 +00:00
| `addShippingZoneAndMethod` | `zoneName` , `zoneLocation` , `zipCode` , `zoneMethod` , `cost` , `additionalZoneMethods` , `testResponse` | Adds a shipping zone along with a shipping method |
| `batchCreateOrders` | `orders` , `testResponse` | Create a batch of orders using the "Batch Create Order" API endpoint |
2021-11-10 09:22:32 +00:00
| `addTaxClasses` | `taxClasses` | Add an array of tax classes if they do not exist |
| `addTaxRates` | `taxRates` | Add an array of tax rates if they do not exist |
| `createProductCategory` | `categoryName` | Create a product category with the provided name |
2021-04-12 17:33:00 +00:00
| `deleteAllCoupons` | | Permanently delete all coupons |
2021-11-10 09:22:32 +00:00
| `deleteAllOrders` | | Permanently delete all orders |
2021-11-15 16:59:28 +00:00
| `deleteAllProductAttributes` | `testResponse` | Permanently delete all product attributes |
| `deleteAllProductCategories` | `testResponse` | Permanently delete all product categories |
2021-04-12 17:33:00 +00:00
| `deleteAllProducts` | | Permanently delete all products |
2021-11-15 16:59:28 +00:00
| `deleteAllProductTags` | `testResponse` | Permanently delete all product tags |
| `deleteAllShippingClasses` | `testResponse` | Permanently delete all shipping classes |
| `deleteAllShippingZones` | `testResponse` | Permanently delete all shipping zones except the default |
2021-11-10 09:22:32 +00:00
| `deleteCoupon` | `couponId` | Permanently delete a coupon |
2021-04-12 17:33:00 +00:00
| `deleteCustomerByEmail` | `emailAddress` | Delete customer user account. Posts are reassigned to user ID 1 |
2022-02-28 07:24:33 +00:00
| `deleteOrder` | `orderId` | Permanently delete an order |
| `deleteProduct` | `productId` | Permanently delete a simple product |
2021-11-10 09:22:32 +00:00
| `getSystemEnvironment` | | Get the current environment from the WooCommerce system status API. |
| `resetOnboarding` | | Reset onboarding settings |
2021-11-15 16:59:28 +00:00
| `resetSettingsGroupToDefault` | `settingsGroup` , `testResponse` | Reset settings in settings group to default except `select` fields |
2021-08-30 18:00:31 +00:00
| `updateSettingOption` | `settingsGroup` , `settingID` , `payload` | Update a settings group |
2021-11-15 16:59:28 +00:00
| `updatePaymentGateway` | `paymentGatewayId` , `payload` , `testResponse` | Update a payment gateway |
2021-04-12 17:33:00 +00:00
2021-09-10 18:56:16 +00:00
### Classes
2021-09-22 15:04:24 +00:00
The package includes the following page specific utility class:
2021-09-10 18:56:16 +00:00
#### AdminEdit
The `AdminEdit` class is the base classic custom post type post editor class. It contains the following functions:
| Function | Parameters | Description |
|----------|------------|-------------|
| `verifyPublish` | `button, publishNotice, publishVerification` | Publish the post object currently being edited and verify publish status |
| `getId` | | Get the ID of the post object being edited |
### General Utilities
There is a general utilities object `utils` with the following functions:
| Function | Parameters | Description |
|----------|------------|-------------|
| `getSlug` | `text` | Take a string name and generate the slug for it |
| `describeIf` | `condition` | Return the `describe` or `describe.skip` function when the condition is true / false |
| `it` | `condition` | Return the `it` or `it.skip` function when the condition is true / false |
| `waitForTimeout` | `timeout` | Wait for a timeout in milliseconds |
2020-10-16 19:25:23 +00:00
### Page Utilities
| Function | Parameters | Description |
|----------|------------|-------------|
2021-01-19 13:00:59 +00:00
| `addProductToOrder` | `orderId, productName` | adds a product to an order using the product search |
2021-03-16 19:57:42 +00:00
| `applyCoupon` | `couponName` | helper method which applies a coupon in cart or checkout |
2020-10-16 19:25:23 +00:00
| `clearAndFillInput` | `selector, value` | Replace the contents of an input with the passed value |
2021-01-19 13:00:59 +00:00
| `clickFilter` | `selector` | helper method that clicks on a list page filter |
2020-10-16 19:25:23 +00:00
| `clickTab` | `tabName` | Click on a WooCommerce -> Settings tab |
2021-03-16 19:57:42 +00:00
| `clickUpdateOrder` | `noticeText` , `waitForSave` | Helper method to click the Update button on the order details page |
| `completeOnboardingWizard` | | completes the onboarding wizard with some default settings |
| `createCoupon` | `couponAmount` , `couponType` | creates a basic coupon. Default amount is 5. Default coupon type is fixed discount. Returns the generated coupon code. |
| `createGroupedProduct` | | creates a grouped product for the grouped product tests. Returns the product id. |
2022-02-28 07:24:33 +00:00
| `createSimpleDownloadableProduct` | `name, downloadLimit, downloadName, price` | Create a simple downloadable product |
2021-01-19 13:00:59 +00:00
| `createSimpleOrder` | `status` | creates a basic order with the provided status string |
2021-03-16 19:57:42 +00:00
| `createSimpleProduct` | | creates the simple product configured in default.json. Returns the product id. |
| `createSimpleProductWithCategory` | `name` , `price` ,`categoryName` | creates a simple product used passed values. Returns the product id. |
| `createVariableProduct` | | creates a variable product for the variable product tests. Returns the product id. |
| `deleteAllEmailLogs` | | deletes the emails generated by WP Mail Logging plugin |
| `evalAndClick` | `selector` | helper method that clicks an element inserted in the DOM by a script |
2022-02-28 07:24:33 +00:00
| `getSelectorAttribute` | `selector, attribute` | Retrieve the desired HTML attribute from a selector |
2021-01-19 13:00:59 +00:00
| `moveAllItemsToTrash` | | helper method that checks every item in a list page and moves them to the trash |
2022-02-28 07:24:33 +00:00
| `orderPageSaveChanges` | | Save the current order page |
2020-10-16 19:25:23 +00:00
| `permalinkSettingsPageSaveChanges` | | Save the current Permalink settings |
2021-03-16 19:57:42 +00:00
| `removeCoupon` | | helper method that removes a single coupon within cart or checkout |
| `selectOptionInSelect2` | `selector, value` | helper method that searchs for select2 type fields and select plus insert value inside |
| `selectOrderAction` | `action` | Helper method to select an order action in the `Order Actions` postbox |
2020-10-16 19:25:23 +00:00
| `setCheckbox` | `selector` | Check a checkbox |
2021-03-16 19:57:42 +00:00
| `settingsPageSaveChanges` | | Save the current WooCommerce settings page |
2020-10-16 19:25:23 +00:00
| `uiUnblocked` | | Wait until the page is unblocked |
2021-03-16 19:57:42 +00:00
| `unsetCheckbox` | `selector` | Uncheck a checkbox |
| `verifyAndPublish` | `noticeText` | Verify that an item can be published |
2020-10-16 19:25:23 +00:00
| `verifyCheckboxIsSet` | `selector` | Verify that a checkbox is checked |
| `verifyCheckboxIsUnset` | `selector` | Verify that a checkbox is unchecked |
2021-03-17 19:40:49 +00:00
| `verifyPublishAndTrash` | `button, publishNotice, publishVerification, trashVerification` | Verify that an item can be published and trashed |
2022-02-28 07:24:33 +00:00
| `verifyValueOfElementAttribute` | `selector, attribute, expectedValue` | Assert the value of the desired HTML attribute of a selector |
2020-10-16 19:25:23 +00:00
| `verifyValueOfInputField` | `selector, value` | Verify an input contains the passed value |
2020-11-27 21:49:20 +00:00
| `clickFilter` | `selector` | Click on a list page filter |
| `moveAllItemsToTrash` | | Moves all items in a list view to the Trash |
2021-03-17 08:07:51 +00:00
| `selectOptionInSelect2` | `selector, value` | helper method that searchs for select2 type fields and select plus insert value inside |
| `searchForOrder` | `value, orderId, customerName` | helper method that searchs for an order via many different terms |
| `addShippingZoneAndMethod` | `zoneName, zoneLocation, zipCode, zoneMethod` | util helper method for adding shipping zones with shipping methods |
| `applyCoupon` | `couponName` | helper method which applies a coupon in cart or checkout |
| `removeCoupon` | | helper method that removes a single coupon within cart or checkout |
2021-03-03 16:57:11 +00:00
| `selectOrderAction` | `action` | Helper method to select an order action in the `Order Actions` postbox |
2021-03-03 22:03:23 +00:00
| `clickUpdateOrder` | `noticeText` , `waitForSave` | Helper method to click the Update button on the order details page |
2021-04-08 10:41:02 +00:00
| `deleteAllShippingZones` | | Delete all the existing shipping zones |
2021-04-27 18:41:50 +00:00
| `waitForSelectorWithoutThrow` | `selector` , `timeoutInSeconds` | conditionally wait for a selector without throwing an error. Default timeout is 5 seconds |
2021-08-17 22:46:22 +00:00
| `createOrder` | `orderOptions` | Creates an order using the API with the passed in details |
2021-11-08 17:38:55 +00:00
| `clickAndWaitForSelector` | `buttonSelector` , `resultSelector` , `timeout` | Click a button and wait for response |
2020-10-16 19:25:23 +00:00
### Test Utilities
2021-03-16 19:57:42 +00:00
As of version 0.1.3, all test utilities from [`@wordpress/e2e-test-utils` ](https://www.npmjs.com/package/@wordpress/e2e-test-utils ) are available through this package.