Skip to content

Commit

Permalink
[ECP-9498] Introduce test case for shopper cancellation (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: Can Demiralp <[email protected]>
  • Loading branch information
candemiralp and Can Demiralp authored Oct 25, 2024
1 parent 862ce00 commit 41d4292
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
13 changes: 10 additions & 3 deletions projects/common/redirect/PayPalPaymentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export class PayPalPaymentPage {
this.passwordInput = page.locator("#password");
this.loginButton = page.locator("#btnLogin");
this.agreeAndPayNowButton = page.locator("#payment-submit-btn");
this.cancelButton = page.locator("#cancelLink");

this.loggingInAnimation = page.locator("#app-loader");
this.cookiesWrapper = page.locator("#ccpaCookieBanner");
this.cookiesDeclineButton = this.cookiesWrapper.getByRole('button', { name: 'decline' });

}

async loginToPayPal(username, password) {
Expand All @@ -35,12 +35,19 @@ export class PayPalPaymentPage {

await this.loggingInAnimation.waitFor({ state: "visible", timeout: 10000 });
await this.loggingInAnimation.waitFor({ state: "hidden", timeout: 15000 });

if (await this.cookiesDeclineButton.isVisible()) {
await this.cookiesDeclineButton.click();
}
await this.cookiesDeclineButton.click();
}

await this.agreeAndPay();
}

async cancelAndGoToStore() {
await this.waitForPopupLoad(this.page);
await this.cancelButton.click();
}

async waitForPopupLoad(page) {
await page.waitForURL(/.*sandbox.paypal.com*/,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { PayPalComponents } from "../../../common/checkoutComponents/PayPalComponents.js";
import { PayPalPaymentPage } from "../../../common/redirect/PayPalPaymentPage.js";
import { PaymentDetailsPage } from "../plugin/PaymentDetails.page.js";

export class PayPalComponentsMagentoPage extends PayPalComponents {
constructor(page) {
super(page);
this.page = page;
}

async payViaPayPal(username, password) {
const popup = await this.initiatePayPalPopup()
await new PayPalPaymentPage(popup).makePayPalPayment(username, password);
}

async cancelPayPal() {
const popup = await this.initiatePayPalPopup();
await new PayPalPaymentPage(popup).cancelAndGoToStore();
}

async initiatePayPalPopup() {
const paymentDetailPage = new PaymentDetailsPage(this.page);
const payPalSection = await paymentDetailPage.selectPayPal();

await this.page.waitForLoadState("load", { timeout: 15000 });

const [popup] = await Promise.all([
this.page.waitForEvent("popup"),
payPalSection.proceedToPayPal(),
]);

return popup;
}
}
9 changes: 9 additions & 0 deletions projects/magento/pageObjects/plugin/PaymentDetails.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { IDealComponents } from "../../../common/checkoutComponents/iDealCompone
import { OneyComponents } from "../../../common/checkoutComponents/OneyComponents.js";
import { GiftcardComponentsMagento } from "../checkout/GiftcardComponentsMagento.js";
import { AmazonPayComponents } from "../../../common/checkoutComponents/AmazonPayComponents.js";
import { expect } from "@playwright/test";

export class PaymentDetailsPage {
constructor(page) {
this.page = page;

this.emailField = page.locator("#customer-email");
this.errorMessage = page.locator(".message-error");

this.creditCardRadioButton = page.locator("#adyen_cc");
this.idealWrapper = page.locator("#adyen-ideal-form");
Expand Down Expand Up @@ -152,4 +154,11 @@ export class PaymentDetailsPage {
await this.page.waitForLoadState("domcontentloaded", { timeout: 15000 });
await this.activePaymentMethod.scrollIntoViewIfNeeded();
}

async verifyPaymentRefusal() {
await this.page.waitForLoadState("domcontentloaded", { timeout: 15000 });
expect(await this.errorMessage.innerText()).toContain(
"The payment is REFUSED."
);
}
}
25 changes: 8 additions & 17 deletions projects/magento/tests/PayPalPayment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,30 @@ import {
} from "../helpers/ScenarioHelper.js";
import { proceedToPaymentAs } from "../helpers/ScenarioHelper.js";
import { PaymentDetailsPage } from "../pageObjects/plugin/PaymentDetails.page.js";
import { PayPalPaymentPage } from "../../common/redirect/PayPalPaymentPage.js";
import { PayPalComponentsMagentoPage } from "../pageObjects/checkout/PayPalComponentsMagento.page.js";

const paymentResources = new PaymentResources();
const users = paymentResources.guestUser;

test.describe("Payment via PayPal", () => {
test.beforeEach(async ({ page }) => {
await goToShippingWithFullCart(page);
await proceedToPaymentAs(page, users.dutch);
});

test("should succeed", async ({ page }) => {
await proceedToPaymentAs(page, users.dutch);

await payViaPayPal(
page,
await new PayPalComponentsMagentoPage(page).payViaPayPal(
paymentResources.payPalUserName,
paymentResources.payPalPassword
);

await verifySuccessfulPayment(page);
});

async function payViaPayPal(page, username, password) {
const paymentDetailPage = new PaymentDetailsPage(page);
const payPalSection = await paymentDetailPage.selectPayPal();

await page.waitForLoadState("load", { timeout: 15000 });

const [popup] = await Promise.all([
page.waitForEvent("popup"),
payPalSection.proceedToPayPal(),
]);
test("should fail if shopper cancels", async ({ page }) => {
await new PayPalComponentsMagentoPage(page).cancelPayPal(page);

await new PayPalPaymentPage(popup).makePayPalPayment(username, password);
}
const paymentDetailPage = new PaymentDetailsPage(page);
await paymentDetailPage.verifyPaymentRefusal();
});
});

0 comments on commit 41d4292

Please sign in to comment.