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..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 @@ -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,17 +42,11 @@ 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/ ); + 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(); @@ -81,17 +75,11 @@ 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/ ); + 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 7a1e353..b64be76 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,17 +45,11 @@ 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(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(); @@ -89,17 +83,11 @@ 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(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 40b04c3..170323c 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,17 +44,11 @@ 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(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(); @@ -91,17 +85,11 @@ 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(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(); @@ -153,7 +141,8 @@ 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 - waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ ); + await checkoutPage.goto( '/shortcode-checkout/' ); + 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 9b20037..50147a1 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(); } @@ -159,21 +169,14 @@ 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/ ); 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('domcontentloaded'); // Pay on Payfast checkout page. waitForURL = page.waitForURL( /\/order-received\// ); @@ -211,3 +214,47 @@ 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.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 ); +} + +/** + * 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.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 ); +}