Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-9498] Introduce test case for shopper cancellation for PayPal #135

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading