From 0b1310cd443a54c6b3f27c4dbbce24fb817bb3bb Mon Sep 17 00:00:00 2001 From: del Date: Wed, 19 May 2021 00:44:33 +0800 Subject: [PATCH 01/14] Remove merchant login/logout calls --- .../specs/merchant/wp-admin-order-apply-coupon.test.js | 2 -- .../merchant/wp-admin-order-customer-payment-page.test.js | 1 - .../core-tests/specs/merchant/wp-admin-order-refund.test.js | 1 - .../specs/merchant/wp-admin-product-edit-details.test.js | 1 - .../core-tests/specs/merchant/wp-admin-product-search.test.js | 1 - .../specs/merchant/wp-admin-settings-shipping-zones.test.js | 1 - .../specs/shopper/front-end-cart-redirection.test.js | 1 - tests/e2e/core-tests/specs/shopper/front-end-cart.test.js | 3 --- .../specs/shopper/front-end-checkout-coupons.test.js | 1 - .../specs/shopper/front-end-checkout-login-account.test.js | 1 - tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js | 1 - .../specs/shopper/front-end-my-account-pay-order.test.js | 1 - .../specs/shopper/front-end-order-email-receiving.test.js | 1 - .../core-tests/specs/shopper/front-end-single-product.test.js | 1 - 14 files changed, 17 deletions(-) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js index 3aa75b25b57..984cd099b6d 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js @@ -4,7 +4,6 @@ * Internal dependencies */ const { - merchant, createSimpleProduct, createSimpleOrder, createCoupon, @@ -26,7 +25,6 @@ let orderId; const runOrderApplyCouponTest = () => { describe('WooCommerce Orders > Apply coupon', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); couponCode = await createCoupon(); orderId = await createSimpleOrder('Pending payment', simpleProductName); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js index 8c597d3ed5a..4809cc993e6 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js @@ -20,7 +20,6 @@ let orderId; const runMerchantOrdersCustomerPaymentPage = () => { describe('WooCommerce Merchant Flow: Orders > Customer Payment Page', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); orderId = await createSimpleOrder(); await addProductToOrder( orderId, simpleProductName ); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js index 0dc0911c8e6..66105f72e2e 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js @@ -45,7 +45,6 @@ const clickAndWaitForSelector = async ( buttonSelector, resultSelector ) => { const runRefundOrderTest = () => { describe('WooCommerce Orders > Refund an order', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); orderId = await createSimpleOrder(); await addProductToOrder(orderId, simpleProductName); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js index 78e4fef92da..1e685b8bb5e 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js @@ -15,7 +15,6 @@ let productId; const runProductEditDetailsTest = () => { describe('Products > Edit Product', () => { beforeAll(async () => { - await merchant.login(); productId = await createSimpleProduct(); }); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js index a9640f303ee..5a050b99886 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js @@ -15,7 +15,6 @@ const simpleProductPrice = config.has('products.simple.price') ? config.get('pro const runProductSearchTest = () => { describe('Products > Search and View a product', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); // Make sure the simple product name is greater than 1 to do a search 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 c6bae31d94f..296ebe4fb2c 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 @@ -34,7 +34,6 @@ const shippingZoneNameSF = 'SF with Local pickup'; const runAddNewShippingZoneTest = () => { describe('WooCommerce Shipping Settings - Add new shipping zone', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); await deleteAllShippingZones(); }); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js index 6f24c50f5ed..2f6d637752c 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js @@ -28,7 +28,6 @@ const runCartRedirectionTest = () => { describe('Cart > Redirect to cart from shop', () => { let simplePostIdValue; beforeAll(async () => { - await merchant.login(); simplePostIdValue = await createSimpleProduct(); // Set checkbox in settings to enable cart redirection diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart.test.js index c9b221fc3cd..e9bc8c8445c 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart.test.js @@ -4,7 +4,6 @@ */ const { shopper, - merchant, createSimpleProduct, uiUnblocked } = require( '@woocommerce/e2e-utils' ); @@ -26,9 +25,7 @@ const twoProductPrice = singleProductPrice * 2; const runCartPageTest = () => { describe('Cart page', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); - await merchant.logout(); }); it('should display no item in the cart', async () => { diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js index a14ce2279e0..8567c21ba39 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js @@ -4,7 +4,6 @@ */ const { shopper, - merchant, createCoupon, createSimpleProduct, uiUnblocked, diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js index db400d5e79d..8c287e72c70 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js @@ -26,7 +26,6 @@ const simpleProductName = config.get('products.simple.name'); const runCheckoutLoginAccountTest = () => { describe('Shopper Checkout Login Account', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); // Set checkbox for logging to account during checkout diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js index 8512b52282b..adc47f7f3c5 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js @@ -27,7 +27,6 @@ let customerOrderId; const runCheckoutPageTest = () => { describe('Checkout page', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(); // Set free shipping within California diff --git a/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js b/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js index ae17eeb617f..90ef8c23260 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js @@ -17,7 +17,6 @@ const simpleProductName = config.get( 'products.simple.name' ); const runMyAccountPayOrderTest = () => { describe('Customer can pay for their order through My Account', () => { beforeAll(async () => { - await merchant.login(); simplePostIdValue = await createSimpleProduct(); await merchant.logout(); await shopper.login(); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js index da466cae6de..163783beafe 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js @@ -29,7 +29,6 @@ const { const runOrderEmailReceivingTest = () => { describe('Shopper Order Email Receiving', () => { beforeAll(async () => { - await merchant.login(); await deleteAllEmailLogs(); simplePostIdValue = await createSimpleProduct(); await merchant.logout(); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js b/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js index 3f914bdd2bc..c7a674fbf35 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js @@ -20,7 +20,6 @@ const simpleProductName = config.get( 'products.simple.name' ); const runSingleProductPageTest = () => { describe('Single Product Page', () => { beforeAll(async () => { - await merchant.login(); simplePostIdValue = await createSimpleProduct(); await merchant.logout(); }); From 6826cce83461d9eeb444286a51f9c410b8e3fb15 Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 00:40:16 +0800 Subject: [PATCH 02/14] Remove merchant login in the remaining shopper test that has it --- .../specs/shopper/front-end-cart-calculate-shipping.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js index 7bdccb60e00..f0c8e02ee02 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js @@ -40,7 +40,6 @@ const shippingCountryFR = 'country:FR'; const runCartCalculateShippingTest = () => { describe('Cart Calculate Shipping', () => { beforeAll(async () => { - await merchant.login(); await createSimpleProduct(firstProductName); await createSimpleProduct(secondProductName, secondProductPrice); await merchant.openNewShipping(); From 22a355c3ce616cfac968704a3a592b7038cdc599 Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 00:42:10 +0800 Subject: [PATCH 03/14] Remove unnecessary merchant util --- .../e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js index b9a285811d1..f2389089819 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js @@ -4,7 +4,6 @@ */ const { shopper, - merchant, createCoupon, createSimpleProduct, uiUnblocked, From ab9532c81b8d31421c1542234734816e7bedca1c Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 16:41:53 +0800 Subject: [PATCH 04/14] Re-add necessary merchant UI login --- .../specs/shopper/front-end-order-email-receiving.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js index 163783beafe..da466cae6de 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js @@ -29,6 +29,7 @@ const { const runOrderEmailReceivingTest = () => { describe('Shopper Order Email Receiving', () => { beforeAll(async () => { + await merchant.login(); await deleteAllEmailLogs(); simplePostIdValue = await createSimpleProduct(); await merchant.logout(); From e7b8591d5c3550494e7f05f54869fa91f979b752 Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 18:14:10 +0800 Subject: [PATCH 05/14] Removed unnecessary merchant logouts based on PR comment --- .../specs/shopper/front-end-my-account-pay-order.test.js | 1 - .../core-tests/specs/shopper/front-end-single-product.test.js | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js b/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js index 90ef8c23260..9ae0790f87f 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-my-account-pay-order.test.js @@ -18,7 +18,6 @@ const runMyAccountPayOrderTest = () => { describe('Customer can pay for their order through My Account', () => { beforeAll(async () => { simplePostIdValue = await createSimpleProduct(); - await merchant.logout(); await shopper.login(); await shopper.goToProduct(simplePostIdValue); await shopper.addToCart(simpleProductName); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js b/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js index c7a674fbf35..8d6fc05e9bd 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-single-product.test.js @@ -21,7 +21,6 @@ const runSingleProductPageTest = () => { describe('Single Product Page', () => { beforeAll(async () => { simplePostIdValue = await createSimpleProduct(); - await merchant.logout(); }); it('should be able to add simple products to the cart', async () => { From d66f1b7075ac47de240ad87c014669f9a5c29bb8 Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 18:27:12 +0800 Subject: [PATCH 06/14] Added necessary merchant login calls --- .../core-tests/specs/shopper/front-end-cart-redirection.test.js | 1 + .../specs/shopper/front-end-checkout-login-account.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js index 2f6d637752c..bff1ada7665 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-redirection.test.js @@ -31,6 +31,7 @@ const runCartRedirectionTest = () => { simplePostIdValue = await createSimpleProduct(); // Set checkbox in settings to enable cart redirection + await merchant.login(); await merchant.openSettings('products'); await setCheckbox('#woocommerce_cart_redirect_after_add'); await settingsPageSaveChanges(); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js index 8c287e72c70..6f8bf2b6b0a 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout-login-account.test.js @@ -29,6 +29,7 @@ const runCheckoutLoginAccountTest = () => { await createSimpleProduct(); // Set checkbox for logging to account during checkout + await merchant.login(); await merchant.openSettings('account'); await setCheckbox('#woocommerce_enable_checkout_login_reminder'); await settingsPageSaveChanges(); From e149dfb12b929c01223008c33c0c219b8d8c41fc Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 18:27:54 +0800 Subject: [PATCH 07/14] Relocated merchant login call to improve readability --- .../specs/shopper/front-end-order-email-receiving.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js index da466cae6de..595879c8973 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-order-email-receiving.test.js @@ -29,9 +29,10 @@ const { const runOrderEmailReceivingTest = () => { describe('Shopper Order Email Receiving', () => { beforeAll(async () => { + simplePostIdValue = await createSimpleProduct(); + await merchant.login(); await deleteAllEmailLogs(); - simplePostIdValue = await createSimpleProduct(); await merchant.logout(); }); From 94f51fe8087b76f1673ea26c939e08b24d7c731b Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 18:41:22 +0800 Subject: [PATCH 08/14] Replace switchUserToTest with merchant.logout --- tests/e2e/config/jest.setup.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index b879aca4516..d19e5c51216 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -1,10 +1,8 @@ -import { SimpleProduct, Coupon } from '@woocommerce/api'; import { visitAdminPage, - switchUserToTest, clearLocalStorage, setBrowserViewport, - withRestApi, + withRestApi } from '@woocommerce/e2e-utils'; const { merchant } = require( '@woocommerce/e2e-utils' ); @@ -35,7 +33,7 @@ async function trashExistingPosts() { await page.waitForXPath( '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' ); - await switchUserToTest(); + await merchant.logout(); } // Before every test suite run, delete all content created by the test. This ensures From d74d37ce676528cb5aefe1f2022d98b04bf9792e Mon Sep 17 00:00:00 2001 From: del Date: Thu, 20 May 2021 23:43:22 +0800 Subject: [PATCH 09/14] Corrected logic prior to merchant logout --- tests/e2e/config/jest.setup.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index d19e5c51216..c1d14ff53fb 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -19,20 +19,19 @@ async function trashExistingPosts() { // If this selector doesn't exist there are no posts for us to delete. const bulkSelector = await page.$( '#bulk-action-selector-top' ); - if ( ! bulkSelector ) { - return; + if ( bulkSelector ) { + // Select all posts. + await page.waitForSelector( '#cb-select-all-1' ); + await page.click( '#cb-select-all-1' ); + // Select the "bulk actions" > "trash" option. + await page.select( '#bulk-action-selector-top', 'trash' ); + // Submit the form to send all draft/scheduled/published posts to the trash. + await page.click( '#doaction' ); + await page.waitForXPath( + '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' + ); } - - // Select all posts. - await page.waitForSelector( '#cb-select-all-1' ); - await page.click( '#cb-select-all-1' ); - // Select the "bulk actions" > "trash" option. - await page.select( '#bulk-action-selector-top', 'trash' ); - // Submit the form to send all draft/scheduled/published posts to the trash. - await page.click( '#doaction' ); - await page.waitForXPath( - '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' - ); + await merchant.logout(); } From 67e7521044c7a57a0bf9287c9967af4150780dd4 Mon Sep 17 00:00:00 2001 From: del Date: Fri, 21 May 2021 01:18:46 +0800 Subject: [PATCH 10/14] Reverted bulk trash logic --- tests/e2e/config/jest.setup.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index c1d14ff53fb..169c2269ba2 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -19,19 +19,21 @@ async function trashExistingPosts() { // If this selector doesn't exist there are no posts for us to delete. const bulkSelector = await page.$( '#bulk-action-selector-top' ); - if ( bulkSelector ) { - // Select all posts. - await page.waitForSelector( '#cb-select-all-1' ); - await page.click( '#cb-select-all-1' ); - // Select the "bulk actions" > "trash" option. - await page.select( '#bulk-action-selector-top', 'trash' ); - // Submit the form to send all draft/scheduled/published posts to the trash. - await page.click( '#doaction' ); - await page.waitForXPath( - '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' - ); + if ( ! bulkSelector ) { + await merchant.logout(); + return; } - + + // Select all posts. + await page.waitForSelector( '#cb-select-all-1' ); + await page.click( '#cb-select-all-1' ); + // Select the "bulk actions" > "trash" option. + await page.select( '#bulk-action-selector-top', 'trash' ); + // Submit the form to send all draft/scheduled/published posts to the trash. + await page.click( '#doaction' ); + await page.waitForXPath( + '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' + ); await merchant.logout(); } From 7751034808cb512b196ee0775d9bbdab976d4927 Mon Sep 17 00:00:00 2001 From: del Date: Fri, 21 May 2021 04:43:29 +0800 Subject: [PATCH 11/14] Added necessary merchant logins --- .../specs/merchant/wp-admin-order-apply-coupon.test.js | 4 ++++ .../merchant/wp-admin-order-customer-payment-page.test.js | 2 ++ .../core-tests/specs/merchant/wp-admin-order-refund.test.js | 2 ++ .../specs/merchant/wp-admin-product-edit-details.test.js | 1 + .../core-tests/specs/merchant/wp-admin-product-search.test.js | 2 ++ .../specs/merchant/wp-admin-settings-shipping-zones.test.js | 1 + .../specs/shopper/front-end-cart-calculate-shipping.test.js | 2 ++ tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js | 1 + 8 files changed, 15 insertions(+) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js index 984cd099b6d..92ac2edefc2 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-apply-coupon.test.js @@ -10,6 +10,7 @@ const { uiUnblocked, addProductToOrder, evalAndClick, + merchant } = require( '@woocommerce/e2e-utils' ); const config = require( 'config' ); @@ -27,7 +28,10 @@ const runOrderApplyCouponTest = () => { beforeAll(async () => { await createSimpleProduct(); couponCode = await createCoupon(); + + await merchant.login(); orderId = await createSimpleOrder('Pending payment', simpleProductName); + await Promise.all([ addProductToOrder(orderId, simpleProductName), diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js index 4809cc993e6..767d12a5dda 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-customer-payment-page.test.js @@ -21,6 +21,8 @@ const runMerchantOrdersCustomerPaymentPage = () => { describe('WooCommerce Merchant Flow: Orders > Customer Payment Page', () => { beforeAll(async () => { await createSimpleProduct(); + + await merchant.login(); orderId = await createSimpleOrder(); await addProductToOrder( orderId, simpleProductName ); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js index 66105f72e2e..1e806316bb1 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-refund.test.js @@ -46,6 +46,8 @@ const runRefundOrderTest = () => { describe('WooCommerce Orders > Refund an order', () => { beforeAll(async () => { await createSimpleProduct(); + + await merchant.login(); orderId = await createSimpleOrder(); await addProductToOrder(orderId, simpleProductName); diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js index 1e685b8bb5e..41cf52e4afb 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-product-edit-details.test.js @@ -16,6 +16,7 @@ const runProductEditDetailsTest = () => { describe('Products > Edit Product', () => { beforeAll(async () => { productId = await createSimpleProduct(); + await merchant.login(); }); it('can edit a product and save the changes', async () => { diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js index 5a050b99886..d397c5685dc 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-product-search.test.js @@ -19,6 +19,8 @@ const runProductSearchTest = () => { // Make sure the simple product name is greater than 1 to do a search await expect(simpleProductName.length).toBeGreaterThan(1); + + await merchant.login(); }); beforeEach(async () => { 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 296ebe4fb2c..2f5b4a19bc0 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 @@ -35,6 +35,7 @@ const runAddNewShippingZoneTest = () => { describe('WooCommerce Shipping Settings - Add new shipping zone', () => { beforeAll(async () => { await createSimpleProduct(); + await merchant.login(); await deleteAllShippingZones(); }); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js index f0c8e02ee02..5c26b217de4 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js @@ -42,6 +42,8 @@ const runCartCalculateShippingTest = () => { beforeAll(async () => { await createSimpleProduct(firstProductName); await createSimpleProduct(secondProductName, secondProductPrice); + + await merchant.login(); await merchant.openNewShipping(); // Add a new shipping zone Germany with Free shipping diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js index adc47f7f3c5..46bf8121eff 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js @@ -30,6 +30,7 @@ const runCheckoutPageTest = () => { await createSimpleProduct(); // Set free shipping within California + await merchant.login(); await addShippingZoneAndMethod('Free Shipping CA', 'state:US:CA', ' ', 'free_shipping'); // Go to general settings page await merchant.openSettings('general'); From e455479db985bdbac11882b17326601369a1af95 Mon Sep 17 00:00:00 2001 From: del Date: Fri, 21 May 2021 04:43:47 +0800 Subject: [PATCH 12/14] Removed unnecessary merchant logout --- tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js index ac283f2f20a..8e7ef988273 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-my-account.test.js @@ -10,7 +10,6 @@ const { const runMyAccountPageTest = () => { describe('My account page', () => { it('allows customer to login', async () => { - await merchant.logout(); await shopper.login(); await expect(page).toMatch('Hello'); await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Dashboard'}); From 8a7f1856529a9e0dec08eec16c54edf1ba86db5d Mon Sep 17 00:00:00 2001 From: del Date: Fri, 21 May 2021 04:55:14 +0800 Subject: [PATCH 13/14] Trash posts using WP API --- tests/e2e/config/jest.setup.js | 45 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index 169c2269ba2..68e2d5382cb 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -1,40 +1,34 @@ import { - visitAdminPage, clearLocalStorage, setBrowserViewport, - withRestApi + withRestApi, + WP_ADMIN_LOGIN } from '@woocommerce/e2e-utils'; -const { merchant } = require( '@woocommerce/e2e-utils' ); +const config = require('config'); +const { HTTPClientFactory } = require('@woocommerce/api'); /** - * Navigates to the post listing screen and bulk-trashes any posts which exist. - * - * @return {Promise} Promise resolving once posts have been trashed. + * Uses the WordPress API to delete all existing posts */ async function trashExistingPosts() { - await merchant.login(); - // Visit `/wp-admin/edit.php` so we can see a list of posts and delete them. - await visitAdminPage( 'edit.php' ); + const apiUrl = config.get('url'); + const wpPostsEndpoint = '/wp/v2/posts'; + const adminUsername = config.get('users.admin.username'); + const adminPassword = config.get('users.admin.password'); + const client = HTTPClientFactory.build(apiUrl) + .withBasicAuth(adminUsername, adminPassword) + .create(); - // If this selector doesn't exist there are no posts for us to delete. - const bulkSelector = await page.$( '#bulk-action-selector-top' ); - if ( ! bulkSelector ) { - await merchant.logout(); - return; + // List all existing posts + const response = await client.get(wpPostsEndpoint); + const posts = response.data; + + // Delete each post + for(const post of posts){ + await client.delete(`${wpPostsEndpoint}/${post.id}`); } - // Select all posts. - await page.waitForSelector( '#cb-select-all-1' ); - await page.click( '#cb-select-all-1' ); - // Select the "bulk actions" > "trash" option. - await page.select( '#bulk-action-selector-top', 'trash' ); - // Submit the form to send all draft/scheduled/published posts to the trash. - await page.click( '#doaction' ); - await page.waitForXPath( - '//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' - ); - await merchant.logout(); } // Before every test suite run, delete all content created by the test. This ensures @@ -44,6 +38,7 @@ beforeAll( async () => { await trashExistingPosts(); await withRestApi.deleteAllProducts(); await withRestApi.deleteAllCoupons(); + await page.goto(WP_ADMIN_LOGIN); await clearLocalStorage(); await setBrowserViewport( 'large' ); } ); From 072af834b9e1480e94368a9e2870f7333e3b0312 Mon Sep 17 00:00:00 2001 From: Rodel Calasagsag Date: Fri, 21 May 2021 19:27:50 +0800 Subject: [PATCH 14/14] Clear browser cache and cookies after each test. Add merchant logins to relevant onboarding & setup tests --- tests/e2e/config/jest.setup.js | 16 ++++++++++++---- .../onboarding-tasklist.test.js | 8 ++++++++ .../specs/activate-and-setup/setup.test.js | 3 +++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index 68e2d5382cb..b750eab855f 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -25,7 +25,7 @@ async function trashExistingPosts() { const posts = response.data; // Delete each post - for(const post of posts){ + for (const post of posts) { await client.delete(`${wpPostsEndpoint}/${post.id}`); } @@ -34,11 +34,19 @@ async function trashExistingPosts() { // Before every test suite run, delete all content created by the test. This ensures // other posts/comments/etc. aren't dirtying tests and tests don't depend on // each other's side-effects. -beforeAll( async () => { +beforeAll(async () => { await trashExistingPosts(); await withRestApi.deleteAllProducts(); await withRestApi.deleteAllCoupons(); await page.goto(WP_ADMIN_LOGIN); await clearLocalStorage(); - await setBrowserViewport( 'large' ); -} ); + await setBrowserViewport('large'); +}); + +// Clear browser cookies and cache using DevTools. +// This is to ensure that each test ends with no user logged in. +afterAll(async () => { + const client = await page.target().createCDPSession(); + await client.send('Network.clearBrowserCookies'); + await client.send('Network.clearBrowserCache'); +}); diff --git a/tests/e2e/core-tests/specs/activate-and-setup/onboarding-tasklist.test.js b/tests/e2e/core-tests/specs/activate-and-setup/onboarding-tasklist.test.js index 47aeecb715f..fefdf853838 100644 --- a/tests/e2e/core-tests/specs/activate-and-setup/onboarding-tasklist.test.js +++ b/tests/e2e/core-tests/specs/activate-and-setup/onboarding-tasklist.test.js @@ -24,6 +24,10 @@ const shippingZoneNameUS = config.get( 'addresses.customer.shipping.country' ); const runOnboardingFlowTest = () => { describe('Store owner can go through store Onboarding', () => { + beforeAll(async () => { + await merchant.login(); + }); + if ( IS_RETEST_MODE ) { it('can reset onboarding to default settings', async () => { await withRestApi.resetOnboarding(); @@ -48,6 +52,10 @@ const runOnboardingFlowTest = () => { const runTaskListTest = () => { describe('Store owner can go through setup Task List', () => { + beforeAll(async () => { + await merchant.login(); + }); + it('can setup shipping', async () => { await page.evaluate(() => { document.querySelector('.woocommerce-list__item-title').scrollIntoView(); diff --git a/tests/e2e/core-tests/specs/activate-and-setup/setup.test.js b/tests/e2e/core-tests/specs/activate-and-setup/setup.test.js index 6ebc3fe961e..1183c8c1077 100644 --- a/tests/e2e/core-tests/specs/activate-and-setup/setup.test.js +++ b/tests/e2e/core-tests/specs/activate-and-setup/setup.test.js @@ -27,6 +27,9 @@ const { const runInitialStoreSettingsTest = () => { describe('Store owner can finish initial store setup', () => { + beforeAll(async () => { + await merchant.login(); + }); it('can enable tax rates and calculations', async () => { // Go to general settings page