mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Refactor openPaypalPopup options, add fundingSource
This commit is contained in:
parent
2c0b436510
commit
39b5673435
1 changed files with 13 additions and 5 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue