diff --git a/.gitignore b/.gitignore index 971f26e..ccc6c02 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ node_modules/ test-results/ playwright-report/ hyva/ -.idea/ \ No newline at end of file +.idea/ + +.env \ No newline at end of file diff --git a/Test/End-2-End/Components/Cart.js b/Test/End-2-End/Components/Cart.js index cc38ab5..ef81d92 100644 --- a/Test/End-2-End/Components/Cart.js +++ b/Test/End-2-End/Components/Cart.js @@ -5,9 +5,9 @@ export default class Cart { this.page = page; } - async addItemToCart(itemName) { - await this.page.goto('./'); - await this.page.locator('button[aria-label="Add to Cart '+itemName+'"]').click(); - await expect(this.page.getByRole('button', { name: 'Toggle minicart, You have 1 product in your cart.'})).toBeVisible(); + async addStandardItemToCart() { + await this.page.goto('./affirm-water-bottle.html'); + await this.page.getByRole('button', { name: 'Add to Cart', exact: true }).click(); + await expect(this.page.getByText(/You added [A-Za-z0-9 ]+ to your shopping cart/i)).toBeVisible(); } } diff --git a/Test/End-2-End/Components/PaypalPopup.js b/Test/End-2-End/Components/PaypalPopup.js new file mode 100644 index 0000000..966fd0e --- /dev/null +++ b/Test/End-2-End/Components/PaypalPopup.js @@ -0,0 +1,17 @@ + +export default class PaypalPopup { + constructor(popup) { + this.popup = popup; + } + + async acceptPayment() { + await this.popup.getByPlaceholder('Email').fill('sb-uqeqf29136249@personal.example.com'); + if(await this.popup.getByRole('button', { name: 'Next' }).isVisible()) { + await this.popup.getByRole('button', {name: 'Next'}).click(); + } + await this.popup.getByPlaceholder('Password').fill('h5Hc/b8M'); + await this.popup.getByRole('button', { name: 'Log In' }).click(); + + await this.popup.getByTestId('submit-button-initial').click(); + } +} diff --git a/Test/End-2-End/Pages/VisitCheckoutPayment.js b/Test/End-2-End/Pages/VisitCheckoutPayment.js index 0b6b5a5..7d33c1e 100644 --- a/Test/End-2-End/Pages/VisitCheckoutPayment.js +++ b/Test/End-2-End/Pages/VisitCheckoutPayment.js @@ -7,8 +7,7 @@ export default class VisitCheckoutPayment { } async visit() { - const cart = new Cart(this.page); - await cart.addItemToCart("Joust Duffle Bag"); + await new Cart(this.page).addStandardItemToCart(); await this.page.goto('./checkout'); diff --git a/Test/End-2-End/card-inline.spec.js b/Test/End-2-End/card-inline.spec.js index 16512e0..d9317a3 100644 --- a/Test/End-2-End/card-inline.spec.js +++ b/Test/End-2-End/card-inline.spec.js @@ -1,7 +1,7 @@ import { test, expect } from '@playwright/test'; import VisitCheckoutPayment from "./Pages/VisitCheckoutPayment"; -test('Can place an order using the inline credit card', async ({ page }) => { +test.skip('Can place an order using the inline credit card', async ({ page }) => { const visitCheckoutPayment = new VisitCheckoutPayment(page); await visitCheckoutPayment.visit(); diff --git a/Test/End-2-End/clearpay.spec.js b/Test/End-2-End/clearpay.spec.js index fa6d9a0..f98ef2f 100644 --- a/Test/End-2-End/clearpay.spec.js +++ b/Test/End-2-End/clearpay.spec.js @@ -57,10 +57,9 @@ test('Renders the Clearpay on the product page', async ({ page }) => { }); test('Renders the Clearpay widget in the checkout', async ({ page }) => { - const cart = new Cart(page); - await cart.addItemToCart("Joust Duffle Bag"); + await new Cart(page).addStandardItemToCart(); - await page.goto('./checkout/cart'); + await page.goto('/checkout/cart'); await expect(page.locator('.afterpay-modal-overlay')).toBeHidden(); diff --git a/Test/End-2-End/paypal.spec.js b/Test/End-2-End/paypal.spec.js index bf1cd52..b7ccb65 100644 --- a/Test/End-2-End/paypal.spec.js +++ b/Test/End-2-End/paypal.spec.js @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import {expect, test} from '@playwright/test'; import VisitCheckoutPayment from "./Pages/VisitCheckoutPayment"; +import PaypalPopup from "./Components/PaypalPopup"; test('Can place an order using PayPal', async ({ page, browser }) => { const visitCheckoutPayment = new VisitCheckoutPayment(page); @@ -8,22 +9,17 @@ test('Can place an order using PayPal', async ({ page, browser }) => { await page.getByLabel('PayPal', { exact: true }).click(); await expect(page.locator('#rvvup-paypal-button-container')).toBeVisible(); + await page.waitForTimeout(2000); - page.on('popup', async popup => { - await popup.waitForLoadState(); - - await popup.getByPlaceholder('Email').fill('sb-uqeqf29136249@personal.example.com'); - await popup.getByPlaceholder('Password').fill('h5Hc/b8M'); - - await popup.getByRole('button', { name: 'Log In' }).click(); - await popup.getByRole('button', { name: 'Complete Purchase' }).click(); - }); - - const paypalFrame = page.frameLocator('#rvvup-paypal-button-container iframe:first-of-type') + const popupPromise = page.waitForEvent('popup'); + const paypalFrame = page.frameLocator('#rvvup-paypal-button-container iframe').first(); await paypalFrame.getByRole('link', { name: 'PayPal' }).click(); + await new PaypalPopup(await popupPromise).acceptPayment(); + await expect(page.locator('#payment-method-view-rvvup_PAYPAL')) .not.toContainText('You are currently paying with PayPal. If you want to cancel this process'); + await expect(page.frameLocator('#rvvup-modal iframe').getByText("Payment being processed")).toBeVisible(); await page.waitForURL("**/checkout/onepage/success/"); @@ -35,20 +31,10 @@ test('Can place an order from the product page using PayPal', async ({ page }) = await page.goto('./joust-duffle-bag.html'); - page.on('popup', async popup => { - await popup.waitForLoadState(); - - await popup.getByPlaceholder('Email').fill('sb-uqeqf29136249@personal.example.com'); - await popup.getByRole('button', { name: 'Next' }).click(); - - await popup.getByPlaceholder('Password').fill('h5Hc/b8M'); - await popup.getByRole('button', { name: 'Log In' }).click(); - - await popup.getByRole('button', { name: 'Continue to review order' }).click(); - }); - - const paypalFrame = page.frameLocator('.rvvup-paypal-express-button-container iframe:first-of-type') + const popupPromise = page.waitForEvent('popup'); + const paypalFrame = page.frameLocator('.rvvup-paypal-express-button-container iframe').first(); await paypalFrame.getByRole('link', { name: 'PayPal' }).click(); + await new PaypalPopup(await popupPromise).acceptPayment(); await page.waitForURL("**/checkout/"); @@ -56,7 +42,7 @@ test('Can place an order from the product page using PayPal', async ({ page }) = await page.getByLabel('Fixed').click(); - visitCheckoutPayment.loadersShouldBeHidden(); + await visitCheckoutPayment.loadersShouldBeHidden(); await page.getByRole('button', { name: 'Proceed to review & payments' }).click(); @@ -69,6 +55,7 @@ test('Can place an order from the product page using PayPal', async ({ page }) = await expect(children.length).toBe(1); await page.getByRole('button', { name: 'Place order' }).click(); + await expect(page.frameLocator('#rvvup-modal iframe').getByText("Payment being processed")).toBeVisible(); await page.waitForURL("**/checkout/onepage/success/"); await expect(page.getByRole('heading', { name: 'Thank you for your purchase!' })).toBeVisible(); });