Add APM tests in pw

This commit is contained in:
Alex P 2023-06-23 10:56:21 +03:00
parent e0a39b1c4e
commit a088c9cabb
No known key found for this signature in database
GPG key ID: 54487A734A204D71
4 changed files with 64 additions and 4 deletions

View file

@ -15,6 +15,8 @@ PRODUCT_ID=123
SUBSCRIPTION_URL="/product/sub"
APM_ID="sofort"
WP_MERCHANT_USER="admin"
WP_MERCHANT_PASSWORD="admin"

View file

@ -1,6 +1,6 @@
const {test, expect} = require('@playwright/test');
const {serverExec} = require("./utils/server");
const {fillCheckoutForm, expectOrderReceivedPage} = require("./utils/checkout");
const {fillCheckoutForm, expectOrderReceivedPage, acceptTerms} = require("./utils/checkout");
const {openPaypalPopup, loginIntoPaypal, waitForPaypalShippingList, completePaypalPayment} = require("./utils/paypal-popup");
const {
@ -11,9 +11,11 @@ const {
PRODUCT_ID,
CHECKOUT_URL,
CHECKOUT_PAGE_ID,
CART_URL,
BLOCK_CHECKOUT_URL,
BLOCK_CHECKOUT_PAGE_ID,
BLOCK_CART_URL,
APM_ID,
} = process.env;
async function completeBlockContinuation(page) {
@ -88,6 +90,47 @@ test.describe('Classic checkout', () => {
await expectOrderReceivedPage(page);
});
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);
});
});
test.describe('Block checkout', () => {

View file

@ -26,6 +26,10 @@ export const fillCheckoutForm = async (page) => {
await differentShippingLocator.uncheck();
}
await acceptTerms(page);
}
export const acceptTerms = async (page) => {
const termsLocator = page.locator('[name="terms"]');
if (await termsLocator.count() > 0) {
await termsLocator.check();

View file

@ -91,9 +91,20 @@ export const waitForPaypalShippingList = async (popup) => {
await expect(popup.locator('#shippingMethodsDropdown')).toBeVisible({timeout: 15000});
}
export const completePaypalPayment = async (popup) => {
/**
* @param popup
* @param {{timeout: ?int, selector: ?string}} options
*/
export const completePaypalPayment = async (popup, options) => {
options = {
...{
timeout: 20000,
selector: '#payment-submit-btn',
},
...options
};
await Promise.all([
popup.waitForEvent('close', {timeout: 20000}),
popup.click('#payment-submit-btn'),
popup.waitForEvent('close', {timeout: options.timeout}),
popup.click(options.selector),
]);
}