From b3c5ebd2430a796517fe6a936e81db15acd0fa74 Mon Sep 17 00:00:00 2001 From: Zenit Shkreli <69572953+zenit2001@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:01:43 +0200 Subject: [PATCH] E2E maintenance (#957) --- tests/playwright/data/paymentData.mjs | 7 -- .../fixtures/countriesEUR/DE.spec.mjs | 23 ++-- tests/playwright/pages/CheckoutPageSFRA6.mjs | 4 +- tests/playwright/pages/PaymentMethodsPage.mjs | 108 +++++++++--------- .../paymentFlows/redirectShopper.mjs | 8 +- 5 files changed, 70 insertions(+), 80 deletions(-) diff --git a/tests/playwright/data/paymentData.mjs b/tests/playwright/data/paymentData.mjs index 8e0ca1936..91440950e 100644 --- a/tests/playwright/data/paymentData.mjs +++ b/tests/playwright/data/paymentData.mjs @@ -1,11 +1,4 @@ export class PaymentData { - GiroPay = { - bankName: 'GENODETT488', - sc: '10', - extensionSc: '4000', - customerIban: 'DE36444488881234567890', - customerName: 'Klaus Giro', - }; SepaDirectDebit = { accountName: 'A. Klaassen', iban: 'NL13TEST0123456789', diff --git a/tests/playwright/fixtures/countriesEUR/DE.spec.mjs b/tests/playwright/fixtures/countriesEUR/DE.spec.mjs index 4fc92b657..7617a2e58 100644 --- a/tests/playwright/fixtures/countriesEUR/DE.spec.mjs +++ b/tests/playwright/fixtures/countriesEUR/DE.spec.mjs @@ -3,9 +3,8 @@ import { regionsEnum } from '../../data/enums.mjs'; import { environments } from '../../data/environments.mjs'; import { RedirectShopper } from '../../paymentFlows/redirectShopper.mjs'; import { ShopperData } from '../../data/shopperData.mjs'; -import { PaymentData } from '../../data/paymentData.mjs'; +import PaymentMethodsPage from '../../pages/PaymentMethodsPage.mjs'; -const paymentData = new PaymentData(); const shopperData = new ShopperData(); let checkoutPage; @@ -29,8 +28,7 @@ for (const environment of environments) { redirectShopper = new RedirectShopper(page); await redirectShopper.doKlarnaPayment(); await checkoutPage.completeCheckout(); - await redirectShopper.completeKlarnaRedirect(true); - await checkoutPage.expectSuccess(); + await new PaymentMethodsPage(page).waitForKlarnaLoad(); }); test('Klarna Fail @quick', async ({ page }) => { @@ -44,8 +42,7 @@ for (const environment of environments) { redirectShopper = new RedirectShopper(page); await redirectShopper.doKlarnaPayNowPayment(); await checkoutPage.completeCheckout(); - await redirectShopper.completeKlarnaPayNowRedirect(true); - await checkoutPage.expectSuccess(); + await new PaymentMethodsPage(page).waitForKlarnaLoad(); }); test('Klarna Pay now Fail', async ({ page }) => { @@ -59,8 +56,7 @@ for (const environment of environments) { redirectShopper = new RedirectShopper(page); await redirectShopper.doKlarnaAccountPayment(); await checkoutPage.completeCheckout(); - await redirectShopper.completeKlarnaAccountRedirect(true); - await checkoutPage.expectSuccess(); + await new PaymentMethodsPage(page).waitForKlarnaLoad(); }); test('Klarna Account Fail', async ({ page }) => { @@ -75,15 +71,20 @@ for (const environment of environments) { redirectShopper = new RedirectShopper(page); await redirectShopper.doGiropayPayment(); await checkoutPage.completeCheckout(); - await redirectShopper.completeGiropayRedirect(paymentData.GiroPay, true); - await checkoutPage.expectNonRedirectSuccess(); + await redirectShopper.completeGiropayRedirect(true); + const popupPromise = page.waitForEvent('popup'); + const popup = await popupPromise; + await popup.waitForNavigation({ + url: /Order-Confirm/, + timeout: 15000, + }); }); test('Giropay Fail', async ({ page }) => { redirectShopper = new RedirectShopper(page); await redirectShopper.doGiropayPayment(page); await checkoutPage.completeCheckout(); - await redirectShopper.completeGiropayRedirect(paymentData.GiroPay, false); + await redirectShopper.completeGiropayRedirect(false); await checkoutPage.expectRefusal(); }); }); diff --git a/tests/playwright/pages/CheckoutPageSFRA6.mjs b/tests/playwright/pages/CheckoutPageSFRA6.mjs index b36e43af1..002eb63a2 100644 --- a/tests/playwright/pages/CheckoutPageSFRA6.mjs +++ b/tests/playwright/pages/CheckoutPageSFRA6.mjs @@ -184,11 +184,11 @@ export default class CheckoutPageSFRA { }; submitPayment = async () => { - await this.page.waitForLoadState('networkidle', { timeout: 15000 }); + await this.page.waitForLoadState('load', { timeout: 15000 }); await this.submitPaymentButton.click(); }; placeOrder = async () => { - await this.page.waitForLoadState('networkidle', { timeout: 15000 }); + await this.page.waitForLoadState('load', { timeout: 15000 }); await this.placeOrderButton.click(); }; diff --git a/tests/playwright/pages/PaymentMethodsPage.mjs b/tests/playwright/pages/PaymentMethodsPage.mjs index b788f2604..3468ff96f 100644 --- a/tests/playwright/pages/PaymentMethodsPage.mjs +++ b/tests/playwright/pages/PaymentMethodsPage.mjs @@ -337,49 +337,37 @@ export default class PaymentMethodsPage { }); }; - async continueOnKlarna() { + async continueOnKlarna(skipModal) { await this.waitForKlarnaLoad(); await this.page.waitForLoadState('networkidle', { timeout: 15000 }); this.klarnaIframe = this.page.frameLocator( - '#klarna-hpp-instance-fullscreen', + '#klarna-apf-iframe', ); - - this.klarnaBuyButton = this.page.locator('#buy-button'); this.klarnaContinueButton = this.klarnaIframe.locator('#onContinue'); this.klarnaVerificationCodeInput = this.klarnaIframe.locator('#otp_field'); + this.klarnaSelectPlanButton = this.klarnaIframe.locator("button[data-testid='pick-plan']"); + this.klarnaBuyButton = this.klarnaIframe.locator("button[data-testid='confirm-and-pay']"); + this.klarnaDirectDebitPlan = this.klarnaIframe.locator("div[id='directdebit.0-ui']"); // used for Klarna Pay Now - await this.klarnaBuyButton.waitFor({ - state: 'visible', - timeout: 15000, - }); - await this.klarnaBuyButton.click(); - - /* Commenting out this section since the phone number comes - prefilled nowadays - await this.klarnaPhoneInput.waitFor({ - state: "visible", - timeout: 15000, - }); - await this.klarnaPhoneInput.fill(); */ - - await this.klarnaContinueButton.waitFor({ - state: 'visible', - timeout: 15000, - }); await this.klarnaContinueButton.click(); await this.klarnaVerificationCodeInput.waitFor({ state: 'visible', timeout: 15000, }); await this.klarnaVerificationCodeInput.fill('123456'); + if (this.klarnaSelectPlanButton.isVisible() && !skipModal) { + await this.klarnaDirectDebitPlan.click(); + await this.klarnaSelectPlanButton.click(); + } + await this.klarnaBuyButton.waitFor({ + state: 'visible', + timeout: 15000, + }); + await this.klarnaBuyButton.click(); } confirmKlarnaPayNowPayment = async () => { await this.continueOnKlarna(); - await this.page - .frameLocator('#klarna-hpp-instance-fullscreen') - .locator('#dd-confirmation-dialog__bottom button') - .click(); }; confirmKlarnaAccountPayment = async () => { @@ -395,12 +383,8 @@ export default class PaymentMethodsPage { .click(); }; - confirmKlarnaPayment = async () => { - await this.continueOnKlarna(); - await this.page - .frameLocator('#klarna-hpp-instance-fullscreen') - .locator('#invoice_kp-purchase-review-continue-button') - .click(); + confirmKlarnaPayment = async (skipModal) => { + await this.continueOnKlarna(skipModal); }; cancelKlarnaDirectEBankingPayment = async () => { @@ -439,39 +423,51 @@ export default class PaymentMethodsPage { cancelKlarnaPayment = async () => { await this.waitForKlarnaLoad(); - await this.page.click('#back-button'); + await this.page.waitForLoadState('networkidle', { timeout: 15000 }); + this.klarnaIframe = this.page.frameLocator( + '#klarna-apf-iframe', + ); + this.firstCancelButton = this.klarnaIframe.locator('#newCollectPhone__navbar__right-icon__icon-wrapper'); + this.secondCancelButton = this.klarnaIframe.locator("button[title='Close']"); + await this.firstCancelButton.waitFor({ + state: 'visible', + timeout: 15000, + }); + await this.firstCancelButton.click(); + await this.secondCancelButton.first().click(); + await this.page.click("button[id='payment-cancel-dialog-express__confirm']"); }; - confirmGiropayPayment = async (giroPayData) => { + confirmGiropayPayment = async () => { await this.page.waitForLoadState('networkidle', { timeout: 15000 }); - const giroBank = this.page.locator('#ui-id-1 li a'); - const giroBankDropdown = this.page.locator('#tags'); + const rejectCookies = this.page.locator('.rds-cookies-overlay__allow-essential-cookies-btn'); + const giroBankDropdown = this.page.locator('#bankSearch'); + const giroBankUl = this.page.getByTestId('bank-group-list').getByRole('button').first(); + const confirmChoice = this.page.getByTestId('bank-result-list').getByRole('button').first(); + const payNow = this.page.locator("button[name='claimCheckoutButton']"); + const confirmPayment = this.page.locator("button[id='submitButton']"); + await rejectCookies.click(); await giroBankDropdown.waitFor({ state: 'visible', timeout: 15000 }); - await giroBankDropdown.type(giroPayData.bankName, { delay: 50 }); - await this.page.waitForLoadState('networkidle', { timeout: 15000 }); - - await giroBank.waitFor({ state: 'visible', timeout: 15000 }); - await giroBank.click(); - await this.page.click('input[name="continueBtn"]'); - await this.page.click('#yes'); - await this.page.locator('input[name="sc"]').type(giroPayData.sc); - await this.page - .locator('input[name="extensionSc"]') - .type(giroPayData.extensionSc); - await this.page - .locator('input[name="customerName1"]') - .type(giroPayData.customerName); - await this.page - .locator('input[name="customerIBAN"]') - .type(giroPayData.customerIban); - await this.page.click('input[value="Absenden"]'); + await giroBankUl.click(); + await confirmChoice.click(); + await payNow.first().click(); + await confirmPayment.waitFor({ + state: 'visible', + timeout: 15000, + }); + await confirmPayment.click(); }; cancelGiropayPayment = async () => { - await this.page.click('#backUrl'); - await this.page.click('.modal-dialog #yes'); + const rejectCookies = this.page.locator('.rds-cookies-overlay__allow-essential-cookies-btn'); + const giroBankDropdown = this.page.locator('#bankSearch'); + const backButton = this.page.locator("button[name='backLink']"); + + await rejectCookies.click(); + await giroBankDropdown.waitFor({ state: 'visible', timeout: 15000 }); + await backButton.click(); }; initiateEPSPayment = async () => { diff --git a/tests/playwright/paymentFlows/redirectShopper.mjs b/tests/playwright/paymentFlows/redirectShopper.mjs index 0abec4f6a..3b6df1b3a 100644 --- a/tests/playwright/paymentFlows/redirectShopper.mjs +++ b/tests/playwright/paymentFlows/redirectShopper.mjs @@ -49,9 +49,9 @@ export class RedirectShopper { await this.paymentMethodsPage.initiateKlarnaPayment(undefined); }; - completeKlarnaRedirect = async (success) => { + completeKlarnaRedirect = async (success, skipModal) => { if (success) { - await this.paymentMethodsPage.confirmKlarnaPayment(); + await this.paymentMethodsPage.confirmKlarnaPayment(skipModal); } else { await this.paymentMethodsPage.cancelKlarnaPayment(); } @@ -93,9 +93,9 @@ export class RedirectShopper { await this.page.click('#rb_giropay'); }; - completeGiropayRedirect = async (paymentData, success) => { + completeGiropayRedirect = async (success) => { if (success) { - await this.paymentMethodsPage.confirmGiropayPayment(paymentData); + await this.paymentMethodsPage.confirmGiropayPayment(); } else { await this.paymentMethodsPage.cancelGiropayPayment(); }