Refactor openPaypalPopup options, add fundingSource

This commit is contained in:
Alex P 2023-06-23 10:54:18 +03:00
parent 2c0b436510
commit 39b5673435
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -8,16 +8,24 @@ const {
/** /**
* Opens the PayPal popup by pressing the button, and returns the popup object. * Opens the PayPal popup by pressing the button, and returns the popup object.
* @param page * @param page
* @param {{timeout: ?int, fundingSource: ?string}} options
* @param {boolean} retry Retries the button click if the popup did not appear after timeout. * @param {boolean} retry Retries the button click if the popup did not appear after timeout.
* @param {int} timeout
*/ */
export const openPaypalPopup = async (page, retry = true, timeout = 5000) => { export const openPaypalPopup = async (page, options = {}, retry = true) => {
options = {
...{
timeout: 5000,
fundingSource: 'paypal',
},
...options
};
try { try {
await page.locator('.component-frame').scrollIntoViewIfNeeded(); await page.locator('.component-frame').scrollIntoViewIfNeeded();
const [popup] = await Promise.all([ const [popup] = await Promise.all([
page.waitForEvent('popup', {timeout}), page.waitForEvent('popup', {timeout: options.timeout}),
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(), page.frameLocator('.component-frame').locator(`[data-funding-source="${options.fundingSource}"]`).click(),
]); ]);
await popup.waitForLoadState(); await popup.waitForLoadState();
@ -41,7 +49,7 @@ export const openPaypalPopup = async (page, retry = true, timeout = 5000) => {
} }
if (retry) { if (retry) {
return openPaypalPopup(page, false); return openPaypalPopup(page, options, false);
} }
throw err; throw err;
} }