Attempt to fix flakiness in shipping test

- Work around Delete and Edit action links not being visible
- delete all shipping zones at beginning of test
- use uiUnBlock instead of page wait
- ensure clicking method edit OK button
This commit is contained in:
Ron Rennick 2021-03-17 14:48:06 -03:00
parent 76ff6fbce3
commit ddb940e993
2 changed files with 26 additions and 16 deletions

View File

@ -11,6 +11,7 @@ const {
clearAndFillInput,
selectOptionInSelect2,
evalAndClick,
uiUnblocked,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
@ -29,14 +30,24 @@ const runAddNewShippingZoneTest = () => {
await createSimpleProduct();
await merchant.openSettings('shipping');
// Check if you can go via blank shipping zones, otherwise remove one existing zone
// This is a workaround to avoid flakyness and to give this test more confidence
// Delete existing shipping zones.
try {
await page.click('.wc-shipping-zones-blank-state > a.wc-shipping-zone-add');
let zone = await page.$( '.wc-shipping-zone-delete' );
if ( zone ) {
// WP action links aren't clickable because they are hidden with a left=-9999 style.
await page.evaluate(() => {
document.querySelector('.wc-shipping-zone-name .row-actions')
.style
.left = '0';
});
while ( zone ) {
await evalAndClick( '.wc-shipping-zone-delete' );
await uiUnblocked();
zone = await page.$( '.wc-shipping-zone-delete' );
}
}
} catch (error) {
await evalAndClick('.wc-shipping-zone-delete');
await page.keyboard.press('Enter');
// Prevent an error here causing the test to fail.
}
});
@ -55,9 +66,9 @@ const runAddNewShippingZoneTest = () => {
await addShippingZoneAndMethod(shippingZoneNameUS);
// Set Flat rate cost
await expect(page).toClick('a.wc-shipping-zone-method-settings', {text: 'Edit'});
await expect(page).toClick('a.wc-shipping-zone-method-settings', {text: 'Flat rate'});
await clearAndFillInput('#woocommerce_flat_rate_cost', '10');
await expect(page).toClick('button#btn-ok');
await expect(page).toClick('.wc-backbone-modal-main button#btn-ok');
await merchant.logout();
});

View File

@ -467,7 +467,7 @@ const createCoupon = async ( couponAmount = '5', discountType = 'Fixed cart disc
*/
const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States (US)', zipCode = ' ', zoneMethod = 'flat_rate' ) => {
await merchant.openNewShipping();
// Fill shipping zone name
await page.waitForSelector('input#zone_name');
await expect(page).toFill('input#zone_name', zoneName);
@ -475,9 +475,9 @@ const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States
// Select shipping zone location
// (.toSelect is not best option here because a lot of &nbsp are present in country/state names)
await expect(page).toFill('#zone_locations', zoneLocation);
await page.waitFor(1000); // avoiding flakiness
await uiUnblocked();
await page.keyboard.press('Tab');
await page.waitFor(1000); // avoiding flakiness
await uiUnblocked();
await page.keyboard.press('Enter');
// Fill shipping zone postcode if needed otherwise just put empty space
@ -488,15 +488,14 @@ const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States
await expect(page).toClick('button#submit');
// Add shipping zone method
await page.waitFor(2000); // avoiding flakiness
await uiUnblocked();
await expect(page).toClick('button.wc-shipping-zone-add-method', {text:'Add shipping method'});
await page.waitFor(2000); // avoiding flakiness
await page.waitForSelector('.wc-shipping-zone-method-description');
await page.waitForSelector('.wc-shipping-zone-method-selector');
await expect(page).toSelect('select[name="add_method_id"]', zoneMethod);
await page.waitFor(1000); // avoiding flakiness
await uiUnblocked();
await expect(page).toClick('button#btn-ok');
await page.waitForSelector('#zone_locations');
await page.waitFor(1000); // avoiding flakiness
await uiUnblocked();
};
/**