Skip to content

Commit

Permalink
Added e2e tests for paypal express (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenit2001 committed Jul 9, 2024
1 parent 6df3c65 commit 311c3c2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<isset name="AdyenConfigs" value="${require('*/cartridge/adyen/utils/adyenConfigs')}" scope="pdict"/>
<isdecorate template="common/layout/checkout">
<isscript>
var assets = require('*/cartridge/scripts/assets.js');
Expand Down Expand Up @@ -34,6 +35,7 @@
<div class="col-sm-7">

<!-- Customer -->
<isif condition="${pdict.AdyenConfigs.getAdyenSFRA6Compatibility()}">
<div class="card customer-summary">
<div class="card-header clearfix">
<h2 class="pull-left card-header-custom">${Resource.msg('heading.checkout.customer', 'checkout', null)}</h2>
Expand All @@ -42,6 +44,7 @@
<isinclude template="checkout/customer/customerSummary" />
</div>
</div>
</isif>

<!-- Shipping -->
<div class="card shipping-summary">
Expand Down
46 changes: 45 additions & 1 deletion tests/playwright/fixtures/USD.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ for (const environment of environments) {

test('PayPal Success @quick', async ({ page }) => {
redirectShopper = new RedirectShopper(page);
await redirectShopper.doPayPalPayment();
await redirectShopper.doPayPalPayment(false, false, true);
await checkoutPage.expectSuccess();
});
});
Expand Down Expand Up @@ -251,4 +251,48 @@ for (const environment of environments) {
await accountPage.expectFailure();
});
});

test.describe.parallel(`${environment.name} USD`, () => {
test.beforeEach(async ({ page }) => {
await page.goto(`${environment.urlExtension}`);
});

test('PayPal Express @quick', async ({ page }) => {
checkoutPage = new environment.CheckoutPage(page);
await checkoutPage.addProductToCart();
await checkoutPage.navigateToCart(regionsEnum.US);
redirectShopper = new RedirectShopper(page);
await redirectShopper.doPayPalPayment(true, false, true);
if (environment.name.indexOf('v5') !== -1) {
await page.locator("button[value='place-order']").click();
await page.locator(".order-thank-you-msg").isVisible({ timeout: 20000 });
}
else {
await checkoutPage.expectSuccess();
}
});

test('PayPal Express shipping change @quick', async ({ page }) => {
checkoutPage = new environment.CheckoutPage(page);
await checkoutPage.addProductToCart();
await checkoutPage.navigateToCart(regionsEnum.US);
redirectShopper = new RedirectShopper(page);
await redirectShopper.doPayPalPayment(true, true, true);
if (environment.name.indexOf('v5') !== -1) {
await page.locator("button[value='place-order']").click();
await page.locator(".order-thank-you-msg").isVisible({ timeout: 20000 });
}
else {
await checkoutPage.expectSuccess();
}
});

test('PayPal Express Cancellation @quick', async ({ page }) => {
checkoutPage = new environment.CheckoutPage(page);
await checkoutPage.addProductToCart();
await checkoutPage.navigateToCart(regionsEnum.US);
redirectShopper = new RedirectShopper(page);
await redirectShopper.doPayPalPayment(true, false, false);
});
});
}
30 changes: 24 additions & 6 deletions tests/playwright/pages/PaymentMethodsPage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ export default class PaymentMethodsPage {
await iDealInput.click();
};

initiatePayPalPayment = async () => {
initiatePayPalPayment = async (expressFlow, shippingChange, success) => {
// Paypal button locator on payment methods page
const payPalButton = this.page
.frameLocator('.adyen-checkout__paypal__button--paypal iframe.visible')
.locator('.paypal-button');

// Click PayPal radio button
await this.page.click('#rb_paypal');
await expect(this.page.locator('.adyen-checkout__paypal__button--paypal iframe.visible'),).toBeVisible({ timeout: 20000 });

if (!expressFlow) {
await this.page.click('#rb_paypal');
}
await expect(this.page.locator('.adyen-checkout__paypal__button--paypal iframe.visible'),).toBeVisible({ timeout: 20000 });

// Capture popup for interaction
const [popup] = await Promise.all([
this.page.waitForEvent('popup'),
Expand All @@ -60,13 +62,29 @@ export default class PaymentMethodsPage {
this.passwordInput = popup.locator('#password');
this.loginButton = popup.locator('#btnLogin');
this.agreeAndPayNowButton = popup.locator('#payment-submit-btn');
this.shippingMethodsDropdown = popup.locator('#shippingMethodsDropdown');
this.cancelButton = popup.locator('a[data-testid="cancel-link"]');

await this.emailInput.click();
await this.emailInput.fill(paymentData.PayPal.username);
await this.nextButton.click();
await this.passwordInput.fill(paymentData.PayPal.password);
await this.loginButton.click();
await this.agreeAndPayNowButton.click();
await this.page.waitForTimeout(5000);

if (shippingChange){
await this.shippingMethodsDropdown.selectOption({ index: 2 }); // This selects the second option as first one is hidden by default in paypal modale
await this.page.waitForTimeout(5000);
}

if (success) {
await this.agreeAndPayNowButton.click();
}
else {
await this.cancelButton.click();
await this.page.goBack();
await expect(this.page.locator('.add-to-cart'),).toBeVisible({ timeout: 20000 });
}
};

initiateAmazonPayment = async (
Expand Down Expand Up @@ -173,7 +191,7 @@ export default class PaymentMethodsPage {

submitSimulator = async (testSuccess) => {
await this.page.locator('button[data-testid="payment-action-button"]').click();
await this.page.locator('button[data-testid="ideal-box-bank-item-TESTNL2A"]').click();
await this.page.locator('div[id="bank-item-TESTNL2A"]').click();
const actionButton = testSuccess ? this.page.getByRole('button', { name: 'Success', exact: true }) : this.page.getByRole('button', { name: 'Cancellation', exact: true });
await actionButton.click();
};
Expand Down
4 changes: 2 additions & 2 deletions tests/playwright/paymentFlows/redirectShopper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class RedirectShopper {
await this.paymentMethodsPage.initiateOneyPayment(shopper);
};

doPayPalPayment = async () => {
await this.paymentMethodsPage.initiatePayPalPayment();
doPayPalPayment = async (expressFlow, shippingChange, success) => {
await this.paymentMethodsPage.initiatePayPalPayment(expressFlow, shippingChange, success);
};

doAmazonPayment = async (normalFlow, selectedCard, success) => {
Expand Down

0 comments on commit 311c3c2

Please sign in to comment.