Add basic tests

This commit is contained in:
Emili Castells Guasch 2023-02-24 17:22:03 +01:00
parent f174e8b8d6
commit 9d460605a8
3 changed files with 84 additions and 6 deletions

View file

@ -1 +1,8 @@
BASEURL="http://example.com" BASEURL="http://example.com"
CUSTOMER_EMAIL="customer@example.com"
CUSTOMER_PASSWORD="password"
CREDIT_CARD_NUMBER="1234567890"
CREDIT_CARD_EXPIRATION="01/2042"
CREDIT_CARD_CVV="123"

View file

@ -1,6 +0,0 @@
const { test, expect } = require('@playwright/test');
test('has title', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/WooCommerce PayPal Payments/);
});

View file

@ -0,0 +1,77 @@
require('dotenv').config();
const {test, expect} = require('@playwright/test');
const {
CUSTOMER_EMAIL,
CUSTOMER_PASSWORD,
CREDIT_CARD_NUMBER,
CREDIT_CARD_EXPIRATION,
CREDIT_CARD_CVV
} = 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);
}
test('PayPal button place order from product page', async ({page}) => {
await page.goto('/product/product/');
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.frameLocator('.component-frame').locator('[data-funding-source="paypal"]').click(),
]);
await popup.waitForLoadState();
await popup.click("text=Log in");
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('#payment-submit-btn').click();
await fillCheckoutForm(page);
await Promise.all([
page.waitForNavigation(),
page.locator('#place_order').click(),
]);
const title = await page.locator('.entry-title');
await expect(title).toHaveText('Order received');
});
test('ACDC', async ({page}) => {
await page.goto('/product/product/');
await page.locator('.single_add_to_cart_button').click();
await page.goto('/checkout/');
await fillCheckoutForm(page);
await page.click("text=Credit Cards");
const creditCardNumber = page.frameLocator('#braintree-hosted-field-number').locator('#credit-card-number');
await creditCardNumber.fill(CREDIT_CARD_NUMBER);
const expirationDate = page.frameLocator('#braintree-hosted-field-expirationDate').locator('#expiration');
await expirationDate.fill(CREDIT_CARD_EXPIRATION);
const cvv = page.frameLocator('#braintree-hosted-field-cvv').locator('#cvv');
await cvv.fill(CREDIT_CARD_CVV);
await Promise.all([
page.waitForNavigation(),
page.locator('.ppcp-dcc-order-button').click(),
]);
const title = await page.locator('.entry-title');
await expect(title).toHaveText('Order received');
});