Skip to content

Commit

Permalink
Update tests to work with sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
aashwin-rvvup committed May 8, 2024
1 parent 4751e09 commit c388a3c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules/
test-results/
playwright-report/
hyva/
.idea/
.idea/

.env
8 changes: 4 additions & 4 deletions Test/End-2-End/Components/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
17 changes: 17 additions & 0 deletions Test/End-2-End/Components/PaypalPopup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

export default class PaypalPopup {
constructor(popup) {
this.popup = popup;
}

async acceptPayment() {
await this.popup.getByPlaceholder('Email').fill('[email protected]');
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();
}
}
3 changes: 1 addition & 2 deletions Test/End-2-End/Pages/VisitCheckoutPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion Test/End-2-End/card-inline.spec.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
5 changes: 2 additions & 3 deletions Test/End-2-End/clearpay.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
39 changes: 13 additions & 26 deletions Test/End-2-End/paypal.spec.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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('[email protected]');
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/");

Expand All @@ -35,28 +31,18 @@ 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('[email protected]');
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/");

await page.getByLabel('Phone number').fill('+447500000000');

await page.getByLabel('Fixed').click();

visitCheckoutPayment.loadersShouldBeHidden();
await visitCheckoutPayment.loadersShouldBeHidden();

await page.getByRole('button', { name: 'Proceed to review & payments' }).click();

Expand All @@ -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();
});

0 comments on commit c388a3c

Please sign in to comment.