mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +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();
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const {test, expect} = require('@playwright/test');
|
||||
const {fillCheckoutForm, loginAsAdmin, loginAsCustomer} = require('./utils');
|
||||
const {loginAsAdmin, loginAsCustomer} = require('./utils/user');
|
||||
const {openPaypalPopup, loginIntoPaypal, completePaypalPayment} = require("./utils/paypal-popup");
|
||||
const {fillCheckoutForm, expectOrderReceivedPage} = require("./utils/checkout");
|
||||
const {
|
||||
AUTHORIZATION,
|
||||
CUSTOMER_EMAIL,
|
||||
CUSTOMER_PASSWORD
|
||||
} = process.env;
|
||||
|
||||
async function purchaseSubscriptionFromCart(page) {
|
||||
|
@ -12,16 +12,9 @@ async function purchaseSubscriptionFromCart(page) {
|
|||
await page.click("text=Sign up now");
|
||||
await page.goto('/cart');
|
||||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
|
||||
]);
|
||||
await popup.waitForLoadState();
|
||||
const popup = await openPaypalPopup(page);
|
||||
await loginIntoPaypal(popup);
|
||||
|
||||
await popup.fill('#email', CUSTOMER_EMAIL);
|
||||
await popup.locator('#btnNext').click();
|
||||
await popup.fill('#password', CUSTOMER_PASSWORD);
|
||||
await popup.locator('#btnLogin').click();
|
||||
await popup.locator('text=Continue').click();
|
||||
await popup.locator('#confirmButtonTop').click();
|
||||
|
||||
|
@ -29,8 +22,7 @@ async function purchaseSubscriptionFromCart(page) {
|
|||
|
||||
await page.locator('text=Sign up now').click();
|
||||
|
||||
const title = page.locator('.entry-title');
|
||||
await expect(title).toHaveText('Order received');
|
||||
await expectOrderReceivedPage(page);
|
||||
}
|
||||
|
||||
test.describe.serial('Subscriptions Merchant', () => {
|
||||
|
@ -208,39 +200,24 @@ test.describe('Subscriber purchase a Subscription', () => {
|
|||
await page.goto('/checkout');
|
||||
await fillCheckoutForm(page);
|
||||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
|
||||
]);
|
||||
await popup.waitForLoadState();
|
||||
const popup = await openPaypalPopup(page);
|
||||
await loginIntoPaypal(popup);
|
||||
|
||||
await popup.fill('#email', CUSTOMER_EMAIL);
|
||||
await popup.locator('#btnNext').click();
|
||||
await popup.fill('#password', CUSTOMER_PASSWORD);
|
||||
await popup.locator('#btnLogin').click();
|
||||
await popup.locator('text=Continue').click();
|
||||
await popup.locator('text=Agree & Subscribe').click();
|
||||
|
||||
await page.waitForTimeout(10000);
|
||||
|
||||
const title = page.locator('.entry-title');
|
||||
await expect(title).toHaveText('Order received');
|
||||
await expectOrderReceivedPage(page);
|
||||
});
|
||||
|
||||
test('Purchase Subscription from Single Product Page', async ({page}) => {
|
||||
await loginAsCustomer(page);
|
||||
await page.goto('/product/subscription');
|
||||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
|
||||
]);
|
||||
await popup.waitForLoadState();
|
||||
const popup = await openPaypalPopup(page);
|
||||
await loginIntoPaypal(popup);
|
||||
|
||||
await popup.fill('#email', CUSTOMER_EMAIL);
|
||||
await popup.locator('#btnNext').click();
|
||||
await popup.fill('#password', CUSTOMER_PASSWORD);
|
||||
await popup.locator('#btnLogin').click();
|
||||
await popup.locator('text=Continue').click();
|
||||
await popup.locator('#confirmButtonTop').click();
|
||||
|
||||
|
@ -248,8 +225,7 @@ test.describe('Subscriber purchase a Subscription', () => {
|
|||
|
||||
await page.locator('text=Sign up now').click();
|
||||
|
||||
const title = page.locator('.entry-title');
|
||||
await expect(title).toHaveText('Order received');
|
||||
await expectOrderReceivedPage(page);
|
||||
});
|
||||
|
||||
test('Purchase Subscription from Cart Page', async ({page}) => {
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
const {
|
||||
WP_MERCHANT_USER,
|
||||
WP_MERCHANT_PASSWORD,
|
||||
WP_CUSTOMER_USER,
|
||||
WP_CUSTOMER_PASSWORD,
|
||||
CUSTOMER_EMAIL,
|
||||
CUSTOMER_FIRST_NAME,
|
||||
CUSTOMER_LAST_NAME,
|
||||
CUSTOMER_COUNTRY,
|
||||
CUSTOMER_ADDRESS,
|
||||
CUSTOMER_POSTCODE,
|
||||
CUSTOMER_CITY,
|
||||
CUSTOMER_PHONE
|
||||
} = process.env;
|
||||
|
||||
async function loginAsAdmin(page) {
|
||||
await page.goto('/wp-admin');
|
||||
await page.locator('input[name="log"]').fill(WP_MERCHANT_USER);
|
||||
await page.locator('input[name="pwd"]').fill(WP_MERCHANT_PASSWORD);
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('text=Log In').click()
|
||||
]);
|
||||
}
|
||||
|
||||
async function loginAsCustomer(page) {
|
||||
await page.goto('/wp-admin');
|
||||
await page.locator('input[name="log"]').fill(WP_CUSTOMER_USER);
|
||||
await page.locator('input[name="pwd"]').fill(WP_CUSTOMER_PASSWORD);
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('text=Log In').click()
|
||||
]);
|
||||
}
|
||||
|
||||
async function fillCheckoutForm(page) {
|
||||
await page.fill('#billing_first_name', CUSTOMER_FIRST_NAME);
|
||||
await page.fill('#billing_last_name', CUSTOMER_LAST_NAME);
|
||||
await page.selectOption('select#billing_country', CUSTOMER_COUNTRY);
|
||||
await page.fill('#billing_address_1', CUSTOMER_ADDRESS);
|
||||
await page.fill('#billing_postcode', CUSTOMER_POSTCODE);
|
||||
await page.fill('#billing_city', CUSTOMER_CITY);
|
||||
await page.fill('#billing_phone', CUSTOMER_PHONE);
|
||||
await page.fill('#billing_email', CUSTOMER_EMAIL);
|
||||
}
|
||||
|
||||
module.exports = {loginAsAdmin, loginAsCustomer, fillCheckoutForm};
|
38
tests/playwright/utils/checkout.js
Normal file
38
tests/playwright/utils/checkout.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import {expect} from "@playwright/test";
|
||||
|
||||
const {
|
||||
CUSTOMER_EMAIL,
|
||||
CUSTOMER_FIRST_NAME,
|
||||
CUSTOMER_LAST_NAME,
|
||||
CUSTOMER_COUNTRY,
|
||||
CUSTOMER_ADDRESS,
|
||||
CUSTOMER_POSTCODE,
|
||||
CUSTOMER_CITY,
|
||||
CUSTOMER_PHONE,
|
||||
} = process.env;
|
||||
|
||||
export const fillCheckoutForm = async (page) => {
|
||||
await page.fill('#billing_first_name', CUSTOMER_FIRST_NAME);
|
||||
await page.fill('#billing_last_name', CUSTOMER_LAST_NAME);
|
||||
await page.selectOption('select#billing_country', CUSTOMER_COUNTRY);
|
||||
await page.fill('#billing_address_1', CUSTOMER_ADDRESS);
|
||||
await page.fill('#billing_postcode', CUSTOMER_POSTCODE);
|
||||
await page.fill('#billing_city', CUSTOMER_CITY);
|
||||
await page.fill('#billing_phone', CUSTOMER_PHONE);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
export const expectOrderReceivedPage = async (page) => {
|
||||
const title = await page.locator('.entry-title');
|
||||
await expect(title).toHaveText('Order received');
|
||||
}
|
59
tests/playwright/utils/paypal-popup.js
Normal file
59
tests/playwright/utils/paypal-popup.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import {expect} from "@playwright/test";
|
||||
|
||||
const {
|
||||
CUSTOMER_EMAIL,
|
||||
CUSTOMER_PASSWORD,
|
||||
} = process.env;
|
||||
|
||||
/**
|
||||
* Opens the PayPal popup by pressing the button, and returns the popup object.
|
||||
* @param page
|
||||
* @param {boolean} retry Retries the button click if the popup did not appear after 5 sec.
|
||||
*/
|
||||
export const openPaypalPopup = async (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;
|
||||
}
|
||||
}
|
||||
|
||||
export const loginIntoPaypal = async (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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits up to 15 sec for the shipping methods list to load.
|
||||
* @param popup
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const waitForPaypalShippingList = async (popup) => {
|
||||
await expect(popup.locator('#shippingMethodsDropdown')).toBeVisible({timeout: 15000});
|
||||
}
|
||||
|
||||
export const completePaypalPayment = async (popup) => {
|
||||
await Promise.all([
|
||||
popup.waitForEvent('close', {timeout: 20000}),
|
||||
popup.click('#payment-submit-btn'),
|
||||
]);
|
||||
}
|
26
tests/playwright/utils/user.js
Normal file
26
tests/playwright/utils/user.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
const {
|
||||
WP_MERCHANT_USER,
|
||||
WP_MERCHANT_PASSWORD,
|
||||
WP_CUSTOMER_USER,
|
||||
WP_CUSTOMER_PASSWORD,
|
||||
} = process.env;
|
||||
|
||||
export const loginAsAdmin = async (page) => {
|
||||
await page.goto('/wp-admin');
|
||||
await page.locator('input[name="log"]').fill(WP_MERCHANT_USER);
|
||||
await page.locator('input[name="pwd"]').fill(WP_MERCHANT_PASSWORD);
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('text=Log In').click()
|
||||
]);
|
||||
}
|
||||
|
||||
export const loginAsCustomer = async (page) => {
|
||||
await page.goto('/wp-admin');
|
||||
await page.locator('input[name="log"]').fill(WP_CUSTOMER_USER);
|
||||
await page.locator('input[name="pwd"]').fill(WP_CUSTOMER_PASSWORD);
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('text=Log In').click()
|
||||
]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue