From c9cd12f5e820ee301717cd97b8c2cf76e1a91b11 Mon Sep 17 00:00:00 2001 From: Veljko Date: Wed, 31 Mar 2021 10:01:41 +0200 Subject: [PATCH 1/2] Fix flakiness in the test --- .../wp-admin-settings-shipping-zones.test.js | 2 +- tests/e2e/utils/src/components.js | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js index 1a49f147158..5ffecc538b2 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js @@ -17,7 +17,7 @@ const { const config = require( 'config' ); const simpleProductPrice = config.has( 'products.simple.price' ) ? config.get( 'products.simple.price' ) : '9.99'; const simpleProductName = config.get( 'products.simple.name' ); -const california = 'California, United States (US)'; +const california = 'state:US:CA'; const sanFranciscoZIP = '94107'; const shippingZoneNameUS = 'US with Flat rate'; const shippingZoneNameFL = 'CA with Free shipping'; diff --git a/tests/e2e/utils/src/components.js b/tests/e2e/utils/src/components.js index cc6de0161fe..24c07fb7417 100644 --- a/tests/e2e/utils/src/components.js +++ b/tests/e2e/utils/src/components.js @@ -464,11 +464,11 @@ const createCoupon = async ( couponAmount = '5', discountType = 'Fixed cart disc * Adds a shipping zone along with a shipping method. * * @param zoneName Shipping zone name. - * @param zoneLocation Shiping zone location. Defaults to United States (US). + * @param zoneLocation Shiping zone location. Defaults to country:US. For states use: state:US:CA * @param zipCode Shipping zone zip code. Defaults to empty one space. * @param zoneMethod Shipping method type. Defaults to flat_rate (use also: free_shipping or local_pickup) */ -const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States (US)', zipCode = ' ', zoneMethod = 'flat_rate' ) => { +const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'country:US', zipCode = ' ', zoneMethod = 'flat_rate' ) => { await merchant.openNewShipping(); // Fill shipping zone name @@ -476,12 +476,7 @@ const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States await expect(page).toFill('input#zone_name', zoneName); // Select shipping zone location - // (.toSelect is not best option here because a lot of   are present in country/state names) - await expect(page).toFill('#zone_locations', zoneLocation); - await uiUnblocked(); - await page.keyboard.press('Tab'); - await uiUnblocked(); - await page.keyboard.press('Enter'); + await expect(page).toSelect('select[name="zone_locations"]', zoneLocation); // Fill shipping zone postcode if needed otherwise just put empty space await page.waitForSelector('a.wc-shipping-zone-postcodes-toggle'); @@ -491,14 +486,12 @@ const addShippingZoneAndMethod = async ( zoneName, zoneLocation = 'United States await expect(page).toClick('button#submit'); // Add shipping zone method - await uiUnblocked(); + await page.waitFor(1000); await expect(page).toClick('button.wc-shipping-zone-add-method', {text:'Add shipping method'}); await page.waitForSelector('.wc-shipping-zone-method-selector'); await expect(page).toSelect('select[name="add_method_id"]', zoneMethod); - await uiUnblocked(); await expect(page).toClick('button#btn-ok'); await page.waitForSelector('#zone_locations'); - await uiUnblocked(); }; /** From 110c31d0786e0426ff3f50f1a7e3564525272ec5 Mon Sep 17 00:00:00 2001 From: Veljko Date: Wed, 31 Mar 2021 10:36:47 +0200 Subject: [PATCH 2/2] Remove unnecessary postcode --- .../specs/merchant/wp-admin-settings-shipping-zones.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js index 5ffecc538b2..e7da3ffe377 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js @@ -90,10 +90,6 @@ const runAddNewShippingZoneTest = () => { await selectOptionInSelect2('New York'); await expect(page).toClick('button[name="calc_shipping"]'); - // Set shipping postcode to 10010 - await clearAndFillInput('#calc_shipping_postcode', '10010'); - await expect(page).toClick('button[name="calc_shipping"]'); - // Verify shipping costs await page.waitForSelector('.order-total'); await expect(page).toMatchElement('.shipping .amount', {text: '$10.00'}); @@ -102,6 +98,7 @@ const runAddNewShippingZoneTest = () => { it('allows customer to benefit from a Free shipping if in CA', async () => { await page.reload(); + // Set shipping state to California await expect(page).toClick('a.shipping-calculator-button'); await expect(page).toClick('#select2-calc_shipping_state-container'); @@ -119,6 +116,7 @@ const runAddNewShippingZoneTest = () => { it('allows customer to benefit from a free Local pickup if in SF', async () => { await page.reload(); + // Set shipping postcode to 94107 await expect(page).toClick('a.shipping-calculator-button'); await clearAndFillInput('#calc_shipping_postcode', '94107');