variation test works to last uncommented step

This commit is contained in:
Ron Rennick 2020-10-20 17:23:09 -03:00
parent bf410cc44e
commit 7a5cad3f99
2 changed files with 128 additions and 15 deletions

View File

@ -0,0 +1,100 @@
# 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
Follow [E2E setup instructions](https://github.com/woocommerce/woocommerce/test/e2e/README.md).
### Setting up core tests
- 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();
```
## Test functions
The functions to access the core tests are:
### Activation and setup
- `runSetupOnboardingTests` - Run all setup and onboarding tests
- `runActivationTest` - Merchant can activate WooCommerce
- `runOnboardingFlowTest` - Merchant can complete onboarding flow
- `runTaskListTest` - Merchant can complete onboarding task list
- `runInitialStoreSettingsTest` - Merchant can complete initial settings
### Merchant
- `runMerchantTests` - Run all merchant tests
- `runCreateCouponTest` - Merchant can create coupon
- `runCreateOrderTest` - Merchant can create order
- `runAddSimpleProductTest` - Merchant can create a simple product
- `runAddVariableProductTest` - Merchant can create a variable product
- `runUpdateGeneralSettingsTest` - Merchant can update general settings
- `runProductSettingsTest` - Merchant can update product settings
- `runTaxSettingsTest` - Merchant can update tax settings
### Shopper
- `runShopperTests` - Run all shopper tests
- `runCartPageTest` - Shopper can view and update cart
- `runCheckoutPageTest` - Shopper can complete checkout
- `runMyAccountPageTest` - Shopper can access my account page
- `runSingleProductPageTest` - Shopper can view single product page
## Contributing a new test
- In your branch create a new `example-test-name.test.js` under the `tests/e2e/core-tests/specs` folder.
- 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;
```
- Add your test to `tests/e2e/core-tests/specs/index.js`
```js
const runExampleTestName = require( './grouping/example-test-name.test' );
// ...
module.exports = {
// ...
runExampleTestName,
}
```

View File

@ -5,7 +5,8 @@
const {
StoreOwnerFlow,
clickTab,
uiUnblocked
uiUnblocked,
setCheckbox
} = require( '@woocommerce/e2e-utils' );
/**
@ -111,13 +112,29 @@ const runAddVariableProductTest = () => {
await page.waitForSelector('select.variation_actions:not([disabled])');
await page.focus('select.variation_actions');
await expect(page).toSelect('select.variation_actions', 'Create variations from all attributes');
await expect( page ).toClick('a.do_variation_action');
// headless: false doesn't require this
const firstDialog = await expect(page).toDisplayDialog(async () => {
// Using this technique since toClick() isn't working.
// See: https://github.com/GoogleChrome/puppeteer/issues/1805#issuecomment-464802876
page.$eval('a.do_variation_action', elem => elem.click());
});
await expect(firstDialog.message()).toMatch('Are you sure you want to link all variations?');
// Set some variation data
await uiUnblocked();
await uiUnblocked();
await page.waitForSelector('.woocommerce_variation');
await page.focus('.variations_tab');
await expect( page ).toClick( '.variations_tab a' );
await page.waitForSelector(
'select[name="attribute_attr-1[0]"]',
{
visible: true,
timeout: 5000
}
);
// Verify that variations were created
await Promise.all([
@ -153,22 +170,17 @@ const runAddVariableProductTest = () => {
expect(page).toMatchElement('select[name="attribute_attr-2[7]"]', {text: 'val2'}),
expect(page).toMatchElement('select[name="attribute_attr-3[7]"]', {text: 'val2'}),
]);
await expect(page).toClick('.woocommerce_variation:nth-of-type(2) .handlediv');
await page.waitFor(2000);
await page.focus('input[name="variable_is_virtual[0]"]');
await expect(page).toClick('input[name="variable_is_virtual[0]"]');
await page.focus( '.variations-pagenav' );
await expect(page).toClick('.variations-pagenav .expand_all');
await page.waitFor( 2000 );
// await setCheckbox('input[name="variable_is_virtual[0]"]');
await expect(page).toFill('input[name="variable_regular_price[0]"]', '9.99');
await expect(page).toClick('.woocommerce_variation:nth-of-type(3) .handlediv');
await page.waitFor(2000);
await page.focus('input[name="variable_is_virtual[1]"]');
await expect(page).toClick('input[name="variable_is_virtual[1]"]');
// await setCheckbox('input[name="variable_is_virtual[1]"]');
await expect(page).toFill('input[name="variable_regular_price[1]"]', '11.99');
await expect(page).toClick('.woocommerce_variation:nth-of-type(4) .handlediv');
await page.waitFor(2000);
await page.focus('input[name="variable_manage_stock[2]"]');
await expect(page).toClick('input[name="variable_manage_stock[2]"]');
// await setCheckbox('input[name="variable_manage_stock[2]"]');
await expect(page).toFill('input[name="variable_regular_price[2]"]', '20');
await expect(page).toFill('input[name="variable_weight[2]"]', '200');
await expect(page).toFill('input[name="variable_length[2]"]', '10');
@ -186,6 +198,7 @@ const runAddVariableProductTest = () => {
'Move to Trash',
'1 product moved to the Trash.'
);
/**/
});
});
};