2020-04-21 11:44:55 +00:00
# WooCommerce End to End Test Utilities
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 () => {
2021-01-19 13:00:59 +00:00
await merchant.login();
2020-04-21 11:44:55 +00:00
await createSimpleProduct();
2021-01-19 13:00:59 +00:00
await merchant.logout();
2020-04-21 11:44:55 +00:00
} );
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
~~~
## Test Function
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 |
|----------|-------------|------------|
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 |
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 |
| `addToCartFromShopPage` | `productTitle` | Add an item to the cart from a single product page |
| `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 |
| `placeOrder` | | Place an order from the checkout page |
| `productIsInCheckout` | `productTitle, quantity, total, cartSubtotal` | Verify product is in cart on checkout page |
| `removeFromCart` | `productTitle` | Remove a product from the cart on the cart page |
| `setCartQuantity` | `productTitle, quantityValue` | Change the quantity of a product on the cart page |
2021-02-05 09:30:25 +00:00
| `searchForProduct` | Searching for a product name and landing on its detail page |
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 |
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-01-19 13:00:59 +00:00
| `createCoupon` | `couponAmount` | creates a basic coupon. Default amount is 5. Returns the generated coupon code. |
| `createSimpleOrder` | `status` | creates a basic order with the provided status string |
| `moveAllItemsToTrash` | | helper method that checks every item in a list page and moves them to the trash |
2020-10-16 19:25:23 +00:00
| `settingsPageSaveChanges` | | Save the current WooCommerce settings page |
| `permalinkSettingsPageSaveChanges` | | Save the current Permalink settings |
| `setCheckbox` | `selector` | Check a checkbox |
| `unsetCheckbox` | `selector` | Uncheck a checkbox |
| `uiUnblocked` | | Wait until the page is unblocked |
| `verifyPublishAndTrash` | `button, publishNotice, publishVerification, trashVerification` | Verify that an item can be published and trashed |
| `verifyCheckboxIsSet` | `selector` | Verify that a checkbox is checked |
| `verifyCheckboxIsUnset` | `selector` | Verify that a checkbox is unchecked |
| `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-01-20 23:19:07 +00:00
| `verifyAndPublish` | `noticeText` | Verify that an item can be published |
2021-02-03 12:13:28 +00:00
| `selectOptionInSelect2` | `selector, value` | helper method that searchs for select2 type fields and select plus insert value inside
2021-02-12 17:19:48 +00:00
| `addShippingZoneAndMethod` | `zoneName, zoneLocation, zipCode, zoneMethod` | util helper method for adding shipping zones with shipping methods
2021-02-11 09:30:39 +00:00
| `applyCoupon` | `couponName` | helper method which applies a coupon in cart or checkout
| `removeCoupon` | | helper method that removes a single coupon within cart or checkout
2020-10-16 19:25:23 +00:00
### Test Utilities
As of version 0.1.2, all test utilities from [`@wordpress/e2e-test-utils` ](https://www.npmjs.com/package/@wordpress/e2e-test-utils ) are available through this package.