From 9d460605a8e7d2ec8f894ffe87971ab59af85256 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 24 Feb 2023 17:22:03 +0100 Subject: [PATCH] Add basic tests --- .env.sample | 7 +++ tests/playwright/example.spec.js | 6 --- tests/playwright/place-order.spec.js | 77 ++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) delete mode 100644 tests/playwright/example.spec.js create mode 100644 tests/playwright/place-order.spec.js diff --git a/.env.sample b/.env.sample index a34939eb4..d29ddcf5f 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1,8 @@ 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" diff --git a/tests/playwright/example.spec.js b/tests/playwright/example.spec.js deleted file mode 100644 index 789a68e19..000000000 --- a/tests/playwright/example.spec.js +++ /dev/null @@ -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/); -}); diff --git a/tests/playwright/place-order.spec.js b/tests/playwright/place-order.spec.js new file mode 100644 index 000000000..2a28fbd2c --- /dev/null +++ b/tests/playwright/place-order.spec.js @@ -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'); +});