mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Extract pw common functions
This commit is contained in:
parent
9b15b70e63
commit
87ac3f1650
6 changed files with 137 additions and 155 deletions
|
@ -1,9 +1,9 @@
|
|||
const {test, expect} = require('@playwright/test');
|
||||
const {serverExec} = require("./utils/server");
|
||||
const {fillCheckoutForm, expectOrderReceivedPage} = require("./utils/checkout");
|
||||
const {openPaypalPopup, loginIntoPaypal, waitForPaypalShippingList, completePaypalPayment} = require("./utils/paypal-popup");
|
||||
|
||||
const {
|
||||
CUSTOMER_EMAIL,
|
||||
CUSTOMER_PASSWORD,
|
||||
CREDIT_CARD_NUMBER,
|
||||
CREDIT_CARD_EXPIRATION,
|
||||
CREDIT_CARD_CVV,
|
||||
|
@ -11,81 +11,11 @@ const {
|
|||
PRODUCT_ID,
|
||||
CHECKOUT_URL,
|
||||
CHECKOUT_PAGE_ID,
|
||||
CART_URL,
|
||||
BLOCK_CHECKOUT_URL,
|
||||
BLOCK_CHECKOUT_PAGE_ID,
|
||||
BLOCK_CART_URL,
|
||||
} = process.env;
|
||||
|
||||
async function fillCheckoutForm(page) {
|
||||
await page.fill('#billing_first_name', 'John');
|
||||
await page.fill('#billing_last_name', 'Doe');
|
||||
await page.selectOption('select#billing_country', 'DE');
|
||||
await page.fill('#billing_address_1', 'Badensche Str. 24');
|
||||
await page.fill('#billing_postcode', '10715');
|
||||
await page.fill('#billing_city', '10715');
|
||||
await page.fill('#billing_phone', '1234567890');
|
||||
await page.fill('#billing_email', CUSTOMER_EMAIL);
|
||||
|
||||
const differentShippingLocator = page.locator('[name="ship_to_different_address"]');
|
||||
if (await differentShippingLocator.count() > 0) {
|
||||
await differentShippingLocator.uncheck();
|
||||
}
|
||||
|
||||
const termsLocator = page.locator('[name="terms"]');
|
||||
if (await termsLocator.count() > 0) {
|
||||
await termsLocator.check();
|
||||
}
|
||||
}
|
||||
|
||||
async function openPaypalPopup(page, retry = true) {
|
||||
try {
|
||||
await page.locator('.component-frame').scrollIntoViewIfNeeded();
|
||||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup', {timeout: 5000}),
|
||||
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
|
||||
]);
|
||||
|
||||
await popup.waitForLoadState();
|
||||
|
||||
return popup;
|
||||
} catch (err) {
|
||||
if (retry) {
|
||||
return openPaypalPopup(page, false);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function loginIntoPaypal(popup) {
|
||||
await Promise.any([
|
||||
popup.locator('[name="login_email"]'),
|
||||
popup.click("text=Log in"),
|
||||
]);
|
||||
|
||||
await popup.fill('[name="login_email"]', CUSTOMER_EMAIL);
|
||||
await popup.locator('#btnNext').click();
|
||||
await popup.fill('[name="login_password"]', CUSTOMER_PASSWORD);
|
||||
await popup.locator('#btnLogin').click();
|
||||
}
|
||||
|
||||
async function waitForPaypalShippingList(popup) {
|
||||
await expect(popup.locator('#shippingMethodsDropdown')).toBeVisible({timeout: 15000});
|
||||
}
|
||||
|
||||
async function completePaypalPayment(popup) {
|
||||
await Promise.all([
|
||||
popup.waitForEvent('close', {timeout: 20000}),
|
||||
popup.click('#payment-submit-btn'),
|
||||
]);
|
||||
}
|
||||
|
||||
async function expectOrderReceivedPage(page) {
|
||||
const title = await page.locator('.entry-title');
|
||||
await expect(title).toHaveText('Order received');
|
||||
}
|
||||
|
||||
async function completeBlockContinuation(page) {
|
||||
await expect(page.locator('#radio-control-wc-payment-method-options-ppcp-gateway')).toBeChecked();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue