woocommerce-paypal-payments/tests/playwright/place-order.spec.js

208 lines
6.2 KiB
JavaScript
Raw Normal View History

2023-02-24 17:22:03 +01:00
const {test, expect} = require('@playwright/test');
const {serverExec} = require("./utils/server");
2023-06-23 10:56:21 +03:00
const {fillCheckoutForm, expectOrderReceivedPage, acceptTerms} = require("./utils/checkout");
2023-05-29 09:47:42 +03:00
const {openPaypalPopup, loginIntoPaypal, waitForPaypalShippingList, completePaypalPayment} = require("./utils/paypal-popup");
2023-03-22 11:24:48 +02:00
2023-02-24 17:22:03 +01:00
const {
CREDIT_CARD_NUMBER,
CREDIT_CARD_EXPIRATION,
2023-03-22 11:24:48 +02:00
CREDIT_CARD_CVV,
PRODUCT_URL,
2023-03-23 09:03:17 +02:00
PRODUCT_ID,
2023-04-27 09:50:32 +03:00
CHECKOUT_URL,
CHECKOUT_PAGE_ID,
2023-06-23 10:56:21 +03:00
CART_URL,
2023-04-27 09:50:32 +03:00
BLOCK_CHECKOUT_URL,
BLOCK_CHECKOUT_PAGE_ID,
2023-04-27 09:50:32 +03:00
BLOCK_CART_URL,
2023-06-23 10:56:21 +03:00
APM_ID,
2023-02-24 17:22:03 +01:00
} = process.env;
2023-04-17 10:23:52 +03:00
async function completeBlockContinuation(page) {
await expect(page.locator('#radio-control-wc-payment-method-options-ppcp-gateway')).toBeChecked();
await expect(page.locator('.component-frame')).toHaveCount(0);
await Promise.all(
page.waitForNavigation(),
page.locator('.wc-block-components-checkout-place-order-button').click(),
);
}
async function expectContinuation(page) {
await expect(page.locator('#payment_method_ppcp-gateway')).toBeChecked();
await expect(page.locator('.component-frame')).toHaveCount(0);
}
2023-04-17 10:23:52 +03:00
async function completeContinuation(page) {
await expectContinuation(page);
2023-04-17 10:23:52 +03:00
await Promise.all([
page.waitForNavigation(),
page.locator('#place_order').click(),
]);
2023-04-17 10:23:52 +03:00
}
test.describe('Classic checkout', () => {
test.beforeAll(async ({ browser }) => {
await serverExec('wp option update woocommerce_checkout_page_id ' + CHECKOUT_PAGE_ID);
});
2023-03-22 11:37:32 +02:00
test('PayPal button place order from Product page', async ({page}) => {
await page.goto(PRODUCT_URL);
2023-03-22 11:37:32 +02:00
const popup = await openPaypalPopup(page);
2023-03-22 11:37:32 +02:00
await loginIntoPaypal(popup);
2023-02-24 17:22:03 +01:00
await completePaypalPayment(popup);
await fillCheckoutForm(page);
2023-02-24 17:22:03 +01:00
await completeContinuation(page);
2023-02-24 17:22:03 +01:00
await expectOrderReceivedPage(page);
});
2023-02-24 17:22:03 +01:00
test('Advanced Credit and Debit Card (ACDC) place order from Checkout page', async ({page}) => {
await page.goto(PRODUCT_URL);
await page.locator('.single_add_to_cart_button').click();
2023-02-24 17:22:03 +01:00
await page.goto(CHECKOUT_URL);
await fillCheckoutForm(page);
2023-02-24 17:22:03 +01:00
await page.click("text=Credit Cards");
2023-02-24 17:22:03 +01:00
const creditCardNumber = page.frameLocator('#braintree-hosted-field-number').locator('#credit-card-number');
await creditCardNumber.fill(CREDIT_CARD_NUMBER);
2023-02-24 17:22:03 +01:00
const expirationDate = page.frameLocator('#braintree-hosted-field-expirationDate').locator('#expiration');
await expirationDate.fill(CREDIT_CARD_EXPIRATION);
2023-02-24 17:22:03 +01:00
const cvv = page.frameLocator('#braintree-hosted-field-cvv').locator('#cvv');
await cvv.fill(CREDIT_CARD_CVV);
2023-02-24 17:22:03 +01:00
await Promise.all([
page.waitForNavigation(),
page.locator('.ppcp-dcc-order-button').click(),
]);
2023-02-24 17:22:03 +01:00
await expectOrderReceivedPage(page);
});
2023-06-23 10:56:21 +03:00
test('PayPal APM button place order', async ({page}) => {
await page.goto(CART_URL + '?add-to-cart=' + PRODUCT_ID);
await page.goto(CHECKOUT_URL);
await fillCheckoutForm(page);
const popup = await openPaypalPopup(page, {fundingSource: APM_ID});
await popup.getByText('Continue', { exact: true }).click();
await completePaypalPayment(popup, {selector: '[name="Successful"]'});
await expectOrderReceivedPage(page);
});
test('PayPal APM button place order when redirect fails', async ({page}) => {
await page.goto(CART_URL + '?add-to-cart=' + PRODUCT_ID);
await page.goto(CHECKOUT_URL);
await fillCheckoutForm(page);
await page.evaluate('PayPalCommerceGateway.ajax.approve_order = null');
const popup = await openPaypalPopup(page, {fundingSource: APM_ID});
await popup.getByText('Continue', { exact: true }).click();
await completePaypalPayment(popup, {selector: '[name="Successful"]'});
await expect(page.locator('.woocommerce-error')).toBeVisible();
await page.reload();
await expectContinuation(page);
await acceptTerms(page);
await completeContinuation(page);
await expectOrderReceivedPage(page);
});
2023-02-24 17:22:03 +01:00
});
2023-03-23 09:03:17 +02:00
test.describe('Block checkout', () => {
test.beforeAll(async ({browser}) => {
await serverExec('wp option update woocommerce_checkout_page_id ' + BLOCK_CHECKOUT_PAGE_ID);
await serverExec('wp pcp settings update blocks_final_review_enabled true');
});
2023-03-23 09:03:17 +02:00
test('PayPal express block checkout', async ({page}) => {
await page.goto('?add-to-cart=' + PRODUCT_ID);
2023-03-23 09:03:17 +02:00
await page.goto(BLOCK_CHECKOUT_URL)
2023-03-23 09:03:17 +02:00
const popup = await openPaypalPopup(page);
2023-03-23 09:03:17 +02:00
await loginIntoPaypal(popup);
2023-03-23 09:03:17 +02:00
await completePaypalPayment(popup);
2023-04-17 17:15:37 +03:00
await completeBlockContinuation(page);
await expectOrderReceivedPage(page);
});
2023-04-17 17:15:37 +03:00
test('PayPal express block cart', async ({page}) => {
await page.goto(BLOCK_CART_URL + '?add-to-cart=' + PRODUCT_ID)
2023-04-17 17:15:37 +03:00
const popup = await openPaypalPopup(page);
2023-04-17 17:15:37 +03:00
await loginIntoPaypal(popup);
2023-04-17 17:15:37 +03:00
await completePaypalPayment(popup);
2023-04-17 17:15:37 +03:00
await completeBlockContinuation(page);
await expectOrderReceivedPage(page);
});
test.describe('Without review', () => {
test.beforeAll(async ({browser}) => {
await serverExec('wp pcp settings update blocks_final_review_enabled false');
});
test('PayPal express block checkout', async ({page}) => {
await page.goto('?add-to-cart=' + PRODUCT_ID);
await page.goto(BLOCK_CHECKOUT_URL)
const popup = await openPaypalPopup(page);
await loginIntoPaypal(popup);
await waitForPaypalShippingList(popup);
await completePaypalPayment(popup);
await expectOrderReceivedPage(page);
});
test('PayPal express block cart', async ({page}) => {
await page.goto(BLOCK_CART_URL + '?add-to-cart=' + PRODUCT_ID)
const popup = await openPaypalPopup(page);
await loginIntoPaypal(popup);
await waitForPaypalShippingList(popup);
await completePaypalPayment(popup);
await expectOrderReceivedPage(page);
});
});
2023-04-17 17:15:37 +03:00
});