From e38f5607959328c5c8335ef68cdba10ecc0a9c70 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 9 Nov 2023 16:00:37 +0530 Subject: [PATCH 1/8] Fix e2e tests: Update default behavior to use a block-based cart and checkout. --- tests/e2e/bin/initialize.sh | 4 +- tests/e2e/config/checkout-block-page.txt | 79 ---------------- tests/e2e/specs/admin/edit-settings.test.js | 8 +- .../cancelled-one-time-payment.test.js | 22 +---- .../payment-flow/one-time-payment.test.js | 22 +---- .../payment-flow/subscription-payment.test.js | 22 +---- tests/e2e/utils/index.js | 92 +++++++++++++++++-- 7 files changed, 106 insertions(+), 143 deletions(-) delete mode 100644 tests/e2e/config/checkout-block-page.txt diff --git a/tests/e2e/bin/initialize.sh b/tests/e2e/bin/initialize.sh index 1a319b6..750b15b 100644 --- a/tests/e2e/bin/initialize.sh +++ b/tests/e2e/bin/initialize.sh @@ -22,4 +22,6 @@ wp-env run tests-cli wp user create customer customer@euvatnumbertestsuite.com - wp-env run tests-cli wp wc tax create -- --country="*" --state="*" --postcode="*" --city="*" --rate=20 --name="General Tax" --user=1 wp-env run tests-cli wp wc product create -- --name="Simple Product" --slug="simple-product" --user=1 --regular_price=10 --virtual=true wp-env run tests-cli wp wc product create -- --name="Simple Subscription Product" --slug="simple-subscription-product" --user=1 --regular_price=10 --type=subscription --virtual=true --meta_data='[{"key":"_subscription_price","value":"10"},{"key":"_subscription_period","value":"month"},{"key":"_subscription_period_interval","value":"1"}]' -wp-env run tests-cli wp post create ./wp-content/plugins/woocommerce-gateway-payfast/tests/e2e/config/checkout-block-page.txt --post_title='Checkout Block' --post_type=page --post_status=publish --post_author=1 + +# Add Shortcode checkout page. +wp-env run tests-cli wp post create --post_title='Shortcode Checkout' --post_type=page --post_status=publish --post_author=1 --post_content='[woocommerce_checkout]' \ No newline at end of file diff --git a/tests/e2e/config/checkout-block-page.txt b/tests/e2e/config/checkout-block-page.txt deleted file mode 100644 index fbb4cba..0000000 --- a/tests/e2e/config/checkout-block-page.txt +++ /dev/null @@ -1,79 +0,0 @@ - -
-
-
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
-
- - - -
-
-
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
-
-
-
- diff --git a/tests/e2e/specs/admin/edit-settings.test.js b/tests/e2e/specs/admin/edit-settings.test.js index a861690..d52410c 100644 --- a/tests/e2e/specs/admin/edit-settings.test.js +++ b/tests/e2e/specs/admin/edit-settings.test.js @@ -44,7 +44,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => { test( 'Checkout Block: Payment method should not available when disabled', async () => { await addProductToCart( {page: checkoutBlockPage, productUrl: '/product/simple-product/'} ); - await checkoutBlockPage.goto( '/checkout-block/' ); + await checkoutBlockPage.goto( '/checkout/' ); const paymentMethodLocator = await checkoutBlockPage.locator( 'label.wc-block-components-radio-control__option', { has: checkoutBlockPage.locator( 'input[value="payfast"]' ) @@ -55,7 +55,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => { test( 'Checkout Page: Payment method should not available when disabled', async () => { await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} ); - await checkoutPage.goto( '/checkout/' ); + await checkoutPage.goto( '/shortcode-checkout/' ); const paymentMethodLocator = await checkoutPage.locator( '.wc_payment_method', { has: checkoutPage.locator( 'input[value="payfast"]' ) @@ -78,7 +78,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => { test( 'Checkout Block: Verify method title & description', async () => { await addProductToCart( {page: checkoutBlockPage, productUrl: '/product/simple-product/'} ); - await checkoutBlockPage.goto( '/checkout-block/' ); + await checkoutBlockPage.goto( '/checkout/' ); const paymentMethodLocator = await checkoutBlockPage.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); @@ -92,7 +92,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => { test( 'Checkout Page: Verify method title & description', async () => { await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} ); - await checkoutPage.goto( '/checkout/' ); + await checkoutPage.goto( '/shortcode-checkout/' ); const paymentMethodLocator = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' ); await expect( paymentMethodLocator ).toHaveText( /Payfast/ ); diff --git a/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js b/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js index 79853f3..8b2e335 100644 --- a/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js +++ b/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import {addProductToCart, changeCurrency, editPayfastSetting, goToOrderEditPage} from '../../utils'; +import {addProductToCart, changeCurrency, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils'; import {customer, payfastSandboxCredentials} from "../../config"; /** @@ -42,14 +42,8 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa const page = checkoutBlock; await addProductToCart( {page, productUrl:'/product/simple-product/'} ); - await page.goto('/checkout-block/'); - - await page.getByLabel('First name').fill( customer.billing.firstname ); - await page.getByLabel('Last name').fill( customer.billing.lastname ); - await page.getByLabel('Address', {exact: true}).fill( customer.billing.addressfirstline ); - await page.getByLabel('City').fill( customer.billing.city ); - await page.getByLabel('Zip Code').fill( customer.billing.postcode ); - await page.getByLabel('Phone (optional)').fill( customer.billing.phone ); + await page.goto('/checkout/'); + await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -81,14 +75,8 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa const page = checkoutPage; await addProductToCart( {page, productUrl: '/product/simple-product/'} ); - await page.goto( '/checkout/' ); - - await page.getByLabel( 'First name' ).fill( customer.billing.firstname ); - await page.getByLabel( 'Last name' ).fill( customer.billing.lastname ); - await page.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline ); - await page.getByLabel( 'Town / City' ).fill( customer.billing.city ); - await page.getByLabel( 'Zip Code' ).fill( customer.billing.postcode ); - await page.getByLabel( 'Phone' ).fill( customer.billing.phone ); + await page.goto( '/shortcode-checkout/' ); + await fillBillingDetails(page, customer.billing); // Check if Payfast payment method is visible & place order const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); diff --git a/tests/e2e/specs/payment-flow/one-time-payment.test.js b/tests/e2e/specs/payment-flow/one-time-payment.test.js index 7a1e353..85bfa0c 100644 --- a/tests/e2e/specs/payment-flow/one-time-payment.test.js +++ b/tests/e2e/specs/payment-flow/one-time-payment.test.js @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import {addProductToCart, changeCurrency, clearEmailLogs, editPayfastSetting, goToOrderEditPage} from '../../utils'; +import {addProductToCart, changeCurrency, clearEmailLogs, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils'; import {customer, payfastSandboxCredentials} from "../../config"; /** @@ -45,14 +45,8 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async await clearEmailLogs( {page: adminPage} ); await addProductToCart( {page: checkoutBlock, productUrl:'/product/simple-product/'} ); - await checkoutBlock.goto('/checkout-block/'); - - await checkoutBlock.getByLabel('First name').fill( customer.billing.firstname ); - await checkoutBlock.getByLabel('Last name').fill( customer.billing.lastname ); - await checkoutBlock.getByLabel('Address', {exact: true}).fill( customer.billing.addressfirstline ); - await checkoutBlock.getByLabel('City').fill( customer.billing.city ); - await checkoutBlock.getByLabel('Zip Code').fill( customer.billing.postcode ); - await checkoutBlock.getByLabel('Phone (optional)').fill( customer.billing.phone ); + await checkoutBlock.goto('/checkout/'); + await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -89,14 +83,8 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async let waitForURL; await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} ); - await checkoutPage.goto( '/checkout/' ); - - await checkoutPage.getByLabel( 'First name' ).fill( customer.billing.firstname ); - await checkoutPage.getByLabel( 'Last name' ).fill( customer.billing.lastname ); - await checkoutPage.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline ); - await checkoutPage.getByLabel( 'Town / City' ).fill( customer.billing.city ); - await checkoutPage.getByLabel( 'Zip Code' ).fill( customer.billing.postcode ); - await checkoutPage.getByLabel( 'Phone' ).fill( customer.billing.phone ); + await checkoutPage.goto( '/shortcode-checkout/' ); + await fillBillingDetails(page, customer.billing); // Check if Payfast payment method is visible & place order waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); diff --git a/tests/e2e/specs/payment-flow/subscription-payment.test.js b/tests/e2e/specs/payment-flow/subscription-payment.test.js index 40b04c3..ab0fd19 100644 --- a/tests/e2e/specs/payment-flow/subscription-payment.test.js +++ b/tests/e2e/specs/payment-flow/subscription-payment.test.js @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import {changeCurrency, editPayfastSetting, goToOrderEditPage} from '../../utils'; +import {changeCurrency, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils'; import {customer, payfastSandboxCredentials} from "../../config"; /** @@ -44,14 +44,8 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await checkoutBlock.goto( '/product/simple-subscription-product/' ); await checkoutBlock.click( 'text=Sign up now' ); - await checkoutBlock.goto( '/checkout-block/' ); - - await checkoutBlock.getByLabel( 'First name' ).fill( customer.billing.firstname ); - await checkoutBlock.getByLabel( 'Last name' ).fill( customer.billing.lastname ); - await checkoutBlock.getByLabel( 'Address', {exact: true} ).fill( customer.billing.addressfirstline ); - await checkoutBlock.getByLabel( 'City' ).fill( customer.billing.city ); - await checkoutBlock.getByLabel( 'Zip Code' ).fill( customer.billing.postcode ); - await checkoutBlock.getByLabel( 'Phone (optional)' ).fill( customer.billing.phone ); + await checkoutBlock.goto( '/checkout/' ); + await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -91,14 +85,8 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await checkoutPage.goto( '/product/simple-subscription-product/' ); await checkoutPage.click( 'text=Sign up now' ); - await checkoutPage.goto( '/checkout/' ); - - await checkoutPage.getByLabel( 'First name' ).fill( customer.billing.firstname ); - await checkoutPage.getByLabel( 'Last name' ).fill( customer.billing.lastname ); - await checkoutPage.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline ); - await checkoutPage.getByLabel( 'Town / City' ).fill( customer.billing.city ); - await checkoutPage.getByLabel( 'Zip Code' ).fill( customer.billing.postcode ); - await checkoutPage.getByLabel( 'Phone' ).fill( customer.billing.phone ); + await checkoutPage.goto( '/shortcode-checkout/' ); + await fillBillingDetails(page, customer.billing); // Check if Payfast payment method is visible & place order waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 9b20037..66474c9 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -159,14 +159,8 @@ export async function processOneTimeOrderWithBlockCheckout( {page, productUrl} ) let waitForURL; await addProductToCart( {page, productUrl} ); - await page.goto( '/checkout-block/' ); - - await page.getByLabel( 'First name' ).fill( customer.billing.firstname ); - await page.getByLabel( 'Last name' ).fill( customer.billing.lastname ); - await page.getByLabel( 'Address', {exact: true} ).fill( customer.billing.addressfirstline ); - await page.getByLabel( 'City' ).fill( customer.billing.city ); - await page.getByLabel( 'Zip Code' ).fill( customer.billing.postcode ); - await page.getByLabel( 'Phone (optional)' ).fill( customer.billing.phone ); + await page.goto( '/checkout/' ); + await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order waitForURL = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -211,3 +205,85 @@ export async function verifyOrderStatusIsProcessing( {page, orderId} ) { export async function goToOrderEditPage( {page, orderId} ){ await page.goto( `/wp-admin/admin.php?page=wc-orders&action=edit&id=${orderId}` ); } + + +/** + * Fill Billing details on block checkout page + * + * @param {Page} page Playwright page object + * @param {Object} customerDetails Customer billing details + */ +export async function blockFillBillingDetails(page, customerDetails) { + const card = await page.locator('.wc-block-components-address-card'); + if (await card.isVisible()) { + await card.locator('a.wc-block-components-address-card__edit').click(); + } + await page.locator('#email').fill(customerDetails.email); + await page.locator('#billing-first_name').fill(customerDetails.firstname); + await page.locator('#billing-last_name').fill(customerDetails.lastname); + await page + .locator('#billing .wc-block-components-country-input input') + .fill(customerDetails.countryName); + await page + .locator('#billing .wc-block-components-country-input ul li') + .first() + .click(); + await page + .locator('#billing-address_1') + .fill(customerDetails.addressfirstline); + await page + .locator('#billing-address_2') + .fill(customerDetails.addresssecondline); + await page.locator('#billing-city').fill(customerDetails.city); + if (customerDetails.state) { + await page + .locator('#billing-state input') + .fill(customerDetails.stateName); + await page.locator('#billing-state ul li').first().click(); + } + await page.locator('#billing-postcode').fill(customerDetails.postcode); +} + +/** + * Fill billing details on checkout page + * + * @param {Page} page Playwright page object + * @param {Object} customerBillingDetails Customer billing details + * @param {boolean} isBlock Is block checkout + */ +export async function fillBillingDetails( + page, + customerBillingDetails, + isBlock = false +) { + if (isBlock) { + return blockFillBillingDetails(page, customerBillingDetails); + } + await page + .locator('#billing_first_name') + .fill(customerBillingDetails.firstname); + await page + .locator('#billing_last_name') + .fill(customerBillingDetails.lastname); + await page.locator('#billing_company').fill(customerBillingDetails.company); + await page + .locator('#billing_country') + .selectOption(customerBillingDetails.country); + await page + .locator('#billing_address_1') + .fill(customerBillingDetails.addressfirstline); + await page + .locator('#billing_address_2') + .fill(customerBillingDetails.addresssecondline); + await page.locator('#billing_city').fill(customerBillingDetails.city); + if (customerBillingDetails.state) { + await page + .locator('#billing_state') + .selectOption(customerBillingDetails.state); + } + await page + .locator('#billing_postcode') + .fill(customerBillingDetails.postcode); + await page.locator('#billing_phone').fill(customerBillingDetails.phone); + await page.locator('#billing_email').fill(customerBillingDetails.email); +} From a3edefc05ac72b0e98295e75ca18118c537962e5 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 9 Nov 2023 16:27:47 +0530 Subject: [PATCH 2/8] Fix page object. --- tests/e2e/specs/payment-flow/one-time-payment.test.js | 4 ++-- tests/e2e/specs/payment-flow/subscription-payment.test.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/e2e/specs/payment-flow/one-time-payment.test.js b/tests/e2e/specs/payment-flow/one-time-payment.test.js index 85bfa0c..8adcca5 100644 --- a/tests/e2e/specs/payment-flow/one-time-payment.test.js +++ b/tests/e2e/specs/payment-flow/one-time-payment.test.js @@ -46,7 +46,7 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async await addProductToCart( {page: checkoutBlock, productUrl:'/product/simple-product/'} ); await checkoutBlock.goto('/checkout/'); - await fillBillingDetails(page, customer.billing, true); + await fillBillingDetails(checkoutBlock, customer.billing, true); // Check if Payfast payment method is visible & place order waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -84,7 +84,7 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} ); await checkoutPage.goto( '/shortcode-checkout/' ); - await fillBillingDetails(page, customer.billing); + await fillBillingDetails(checkoutPage, customer.billing); // Check if Payfast payment method is visible & place order waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); diff --git a/tests/e2e/specs/payment-flow/subscription-payment.test.js b/tests/e2e/specs/payment-flow/subscription-payment.test.js index ab0fd19..ab94b2a 100644 --- a/tests/e2e/specs/payment-flow/subscription-payment.test.js +++ b/tests/e2e/specs/payment-flow/subscription-payment.test.js @@ -45,7 +45,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await checkoutBlock.goto( '/product/simple-subscription-product/' ); await checkoutBlock.click( 'text=Sign up now' ); await checkoutBlock.goto( '/checkout/' ); - await fillBillingDetails(page, customer.billing, true); + await fillBillingDetails(checkoutBlock, customer.billing, true); // Check if Payfast payment method is visible & place order waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -86,7 +86,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await checkoutPage.goto( '/product/simple-subscription-product/' ); await checkoutPage.click( 'text=Sign up now' ); await checkoutPage.goto( '/shortcode-checkout/' ); - await fillBillingDetails(page, customer.billing); + await fillBillingDetails(checkoutPage, customer.billing); // Check if Payfast payment method is visible & place order waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); @@ -141,6 +141,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await checkoutPage.getByRole( 'link', {name: 'Renew now'} ).click(); // Check if Payfast payment method is visible & place order + await checkoutPage.goto( '/shortcode-checkout/' ); waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' ); await payfastPaymentMethod.click(); From f722159ae7f1c225f37bfa6e04bdcb6649566845 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 9 Nov 2023 16:57:54 +0530 Subject: [PATCH 3/8] Update fillBilling details functions. --- tests/e2e/utils/index.js | 64 ++++++++-------------------------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 66474c9..9eb514d 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -218,30 +218,13 @@ export async function blockFillBillingDetails(page, customerDetails) { if (await card.isVisible()) { await card.locator('a.wc-block-components-address-card__edit').click(); } - await page.locator('#email').fill(customerDetails.email); - await page.locator('#billing-first_name').fill(customerDetails.firstname); - await page.locator('#billing-last_name').fill(customerDetails.lastname); - await page - .locator('#billing .wc-block-components-country-input input') - .fill(customerDetails.countryName); - await page - .locator('#billing .wc-block-components-country-input ul li') - .first() - .click(); - await page - .locator('#billing-address_1') - .fill(customerDetails.addressfirstline); - await page - .locator('#billing-address_2') - .fill(customerDetails.addresssecondline); - await page.locator('#billing-city').fill(customerDetails.city); - if (customerDetails.state) { - await page - .locator('#billing-state input') - .fill(customerDetails.stateName); - await page.locator('#billing-state ul li').first().click(); - } - await page.locator('#billing-postcode').fill(customerDetails.postcode); + + await page.getByLabel( 'First name' ).fill( customerDetails.firstname ); + await page.getByLabel( 'Last name' ).fill( customerDetails.lastname ); + await page.getByLabel( 'Address', {exact: true} ).fill( customerDetails.addressfirstline ); + await page.getByLabel( 'City' ).fill( customerDetails.city ); + await page.getByLabel( 'Zip Code' ).fill( customerDetails.postcode ); + await page.getByLabel( 'Phone (optional)' ).fill( customerDetails.phone ); } /** @@ -259,31 +242,10 @@ export async function fillBillingDetails( if (isBlock) { return blockFillBillingDetails(page, customerBillingDetails); } - await page - .locator('#billing_first_name') - .fill(customerBillingDetails.firstname); - await page - .locator('#billing_last_name') - .fill(customerBillingDetails.lastname); - await page.locator('#billing_company').fill(customerBillingDetails.company); - await page - .locator('#billing_country') - .selectOption(customerBillingDetails.country); - await page - .locator('#billing_address_1') - .fill(customerBillingDetails.addressfirstline); - await page - .locator('#billing_address_2') - .fill(customerBillingDetails.addresssecondline); - await page.locator('#billing_city').fill(customerBillingDetails.city); - if (customerBillingDetails.state) { - await page - .locator('#billing_state') - .selectOption(customerBillingDetails.state); - } - await page - .locator('#billing_postcode') - .fill(customerBillingDetails.postcode); - await page.locator('#billing_phone').fill(customerBillingDetails.phone); - await page.locator('#billing_email').fill(customerBillingDetails.email); + await page.getByLabel( 'First name' ).fill( customerDetails.firstname ); + await page.getByLabel( 'Last name' ).fill( customerDetails.lastname ); + await page.getByLabel( 'Street address' ).fill( customerDetails.addressfirstline ); + await page.getByLabel( 'Town / City' ).fill( customerDetails.city ); + await page.getByLabel( 'Zip Code' ).fill( customerDetails.postcode ); + await page.getByLabel( 'Phone' ).fill( customerDetails.phone ); } From 843922134521171907b1d092ff9def529f6d5f8f Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 9 Nov 2023 17:55:18 +0530 Subject: [PATCH 4/8] Fix varialbe name. --- tests/e2e/utils/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 9eb514d..1016ea7 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -242,10 +242,10 @@ export async function fillBillingDetails( if (isBlock) { return blockFillBillingDetails(page, customerBillingDetails); } - await page.getByLabel( 'First name' ).fill( customerDetails.firstname ); - await page.getByLabel( 'Last name' ).fill( customerDetails.lastname ); - await page.getByLabel( 'Street address' ).fill( customerDetails.addressfirstline ); - await page.getByLabel( 'Town / City' ).fill( customerDetails.city ); - await page.getByLabel( 'Zip Code' ).fill( customerDetails.postcode ); - await page.getByLabel( 'Phone' ).fill( customerDetails.phone ); + await page.getByLabel( 'First name' ).fill( customerBillingDetails.firstname ); + await page.getByLabel( 'Last name' ).fill( customerBillingDetails.lastname ); + await page.getByLabel( 'Street address' ).fill( customerBillingDetails.addressfirstline ); + await page.getByLabel( 'Town / City' ).fill( customerBillingDetails.city ); + await page.getByLabel( 'Zip Code' ).fill( customerBillingDetails.postcode ); + await page.getByLabel( 'Phone' ).fill( customerBillingDetails.phone ); } From 43d506a42dd43dcbe7f5b53241b83a2c10a37be2 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 9 Nov 2023 19:48:39 +0530 Subject: [PATCH 5/8] tests: get home url from node env --- tests/e2e/utils/index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 1016ea7..01b879f 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -125,10 +125,15 @@ export async function addProductToCart( {page, productUrl} ) { * @param {Page} page */ export async function clearEmailLogs( {page} ) { - const result = await page.evaluate( async() => { - const response = await fetch( `${window.location.origin}/wp-json/e2e-wc/v1/flush-all-emails`, {method: 'DELETE'} ); - return await response.json(); - }); + const pageUrl = process.env.baseURL; + const result = await page.evaluate( + async ( pageUrl ) => { + const response = await fetch( + `${pageUrl}/wp-json/e2e-wc/v1/flush-all-emails`, + {method: 'DELETE'} + ); + return await response.json(); + }, pageUrl ); await expect( result ).toBeTruthy(); } @@ -139,10 +144,15 @@ export async function clearEmailLogs( {page} ) { * @param {Page} page */ export async function clearWooCommerceLogs( {page} ) { - const result = await page.evaluate( async() => { - const response = await fetch( `${window.location.origin}/wp-json/e2e-wc/v1/flush-all-logs`, {method: 'DELETE'} ); - return await response.json(); - }); + const pageUrl = process.env.baseURL; + const result = await page.evaluate( + async ( pageUrl ) => { + const response = await fetch( + `${pageUrl}/wp-json/e2e-wc/v1/flush-all-logs`, + {method: 'DELETE'} + ); + return await response.json(); + }, pageUrl ); await expect( result ).toBeTruthy(); } From d68fae34aa03d64d86274a865a5d4e5becb8ba86 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 9 Nov 2023 20:33:16 +0530 Subject: [PATCH 6/8] Update payfast process payment url. --- .../specs/payment-flow/cancelled-one-time-payment.test.js | 4 ++-- tests/e2e/specs/payment-flow/one-time-payment.test.js | 4 ++-- tests/e2e/specs/payment-flow/subscription-payment.test.js | 6 +++--- tests/e2e/utils/index.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js b/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js index 8b2e335..0c39e31 100644 --- a/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js +++ b/tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js @@ -46,7 +46,7 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order - const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await page.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); await page.getByRole( 'button', {name: 'Place order'} ).click(); @@ -79,7 +79,7 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa await fillBillingDetails(page, customer.billing); // Check if Payfast payment method is visible & place order - const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await page.locator( '.wc_payment_method.payment_method_payfast' ); await payfastPaymentMethod.click(); await page.getByRole( 'button', {name: 'Place order'} ).click(); diff --git a/tests/e2e/specs/payment-flow/one-time-payment.test.js b/tests/e2e/specs/payment-flow/one-time-payment.test.js index 8adcca5..b64be76 100644 --- a/tests/e2e/specs/payment-flow/one-time-payment.test.js +++ b/tests/e2e/specs/payment-flow/one-time-payment.test.js @@ -49,7 +49,7 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async await fillBillingDetails(checkoutBlock, customer.billing, true); // Check if Payfast payment method is visible & place order - waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await checkoutBlock.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); await checkoutBlock.getByRole( 'button', {name: 'Place order'} ).click(); @@ -87,7 +87,7 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async await fillBillingDetails(checkoutPage, customer.billing); // Check if Payfast payment method is visible & place order - waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' ); await payfastPaymentMethod.click(); await checkoutPage.getByRole( 'button', {name: 'Place order'} ).click(); diff --git a/tests/e2e/specs/payment-flow/subscription-payment.test.js b/tests/e2e/specs/payment-flow/subscription-payment.test.js index ab94b2a..170323c 100644 --- a/tests/e2e/specs/payment-flow/subscription-payment.test.js +++ b/tests/e2e/specs/payment-flow/subscription-payment.test.js @@ -48,7 +48,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await fillBillingDetails(checkoutBlock, customer.billing, true); // Check if Payfast payment method is visible & place order - waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await checkoutBlock.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); @@ -89,7 +89,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as await fillBillingDetails(checkoutPage, customer.billing); // Check if Payfast payment method is visible & place order - waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' ); await payfastPaymentMethod.click(); await checkoutPage.getByRole( 'button', {name: 'Sign up now'} ).click(); @@ -142,7 +142,7 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as // Check if Payfast payment method is visible & place order await checkoutPage.goto( '/shortcode-checkout/' ); - waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' ); await payfastPaymentMethod.click(); await checkoutPage.getByRole( 'button', {name: 'Renew Subscription'} ).click(); diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 1016ea7..0e89b02 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -163,7 +163,7 @@ export async function processOneTimeOrderWithBlockCheckout( {page, productUrl} ) await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order - waitForURL = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + waitForURL = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await page.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); await page.getByRole( 'button', {name: 'Place order'} ).click(); From c6c267d218de68430399d22f0e821a511dd474ea Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 9 Nov 2023 21:15:47 +0530 Subject: [PATCH 7/8] tests: wait for load state instead of url --- tests/e2e/utils/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index 9ba4610..c137d7b 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -173,11 +173,10 @@ export async function processOneTimeOrderWithBlockCheckout( {page, productUrl} ) await fillBillingDetails(page, customer.billing, true); // Check if Payfast payment method is visible & place order - waitForURL = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ ); const payfastPaymentMethod = await page.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); await page.getByRole( 'button', {name: 'Place order'} ).click(); - await waitForURL; + await page.waitForLoadState({state: 'domcontentloaded'}); // Pay on Payfast checkout page. waitForURL = page.waitForURL( /\/order-received\// ); From 2dd62b7630eeded4bce6686943e07454678d618a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 9 Nov 2023 21:21:10 +0530 Subject: [PATCH 8/8] tests: wait for load state instead of navigation to prevent flanky test --- tests/e2e/utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/index.js b/tests/e2e/utils/index.js index c137d7b..50147a1 100644 --- a/tests/e2e/utils/index.js +++ b/tests/e2e/utils/index.js @@ -176,7 +176,7 @@ export async function processOneTimeOrderWithBlockCheckout( {page, productUrl} ) const payfastPaymentMethod = await page.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' ); await payfastPaymentMethod.click(); await page.getByRole( 'button', {name: 'Place order'} ).click(); - await page.waitForLoadState({state: 'domcontentloaded'}); + await page.waitForLoadState('domcontentloaded'); // Pay on Payfast checkout page. waitForURL = page.waitForURL( /\/order-received\// );