From c4605fbcbacc18e7ae925d6eb36cd5ba8b394203 Mon Sep 17 00:00:00 2001 From: Yu Long Date: Tue, 26 Nov 2024 14:13:32 +0100 Subject: [PATCH] test(stored-card-maestro): added --- packages/e2e-playwright/models/dropin.ts | 4 +- packages/e2e-playwright/playwright.config.ts | 2 +- .../e2e-playwright/tests/e2e/card/avs.spec.ts | 5 ++- .../storedCard/stored-card-amex.spec.ts | 2 +- .../storedCard/stored-card-maestro.spec.ts | 43 +++++++++++++++++-- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/packages/e2e-playwright/models/dropin.ts b/packages/e2e-playwright/models/dropin.ts index 3ea57a0d1..fade04e1f 100644 --- a/packages/e2e-playwright/models/dropin.ts +++ b/packages/e2e-playwright/models/dropin.ts @@ -50,10 +50,10 @@ class Dropin extends Base { // Stored payment methods async selectFirstStoredPaymentMethod(pmType: string, lastFour?: string) { - const pmLabel = this.paymentMethods.find((pm: { type: string }) => pm.type === pmType).name; + const pmLabel = this.paymentMethods.find((pm: { type: string }) => pm.type === pmType)?.name; await this.page .locator('.adyen-checkout__payment-method') - .filter({ has: this.page.getByRole('img', { name: pmLabel }) }) // filter the payment methods which have the correct logo + .filter({ has: this.page.getByRole('img', { name: pmLabel ?? pmType }) }) // filter the payment methods which have the correct logo .getByRole('radio', { name: lastFour, exact: false }) .first() .click(); diff --git a/packages/e2e-playwright/playwright.config.ts b/packages/e2e-playwright/playwright.config.ts index 75a2ce162..b051d322e 100644 --- a/packages/e2e-playwright/playwright.config.ts +++ b/packages/e2e-playwright/playwright.config.ts @@ -44,7 +44,7 @@ const config: PlaywrightTestConfig = { trace: 'on-first-retry', ignoreHTTPSErrors: true, screenshot: 'only-on-failure', - video: 'on-first-retry' + video: 'retain-on-failure' }, /* Configure projects for major browsers */ diff --git a/packages/e2e-playwright/tests/e2e/card/avs.spec.ts b/packages/e2e-playwright/tests/e2e/card/avs.spec.ts index eb774d06f..a5ebb1628 100644 --- a/packages/e2e-playwright/tests/e2e/card/avs.spec.ts +++ b/packages/e2e-playwright/tests/e2e/card/avs.spec.ts @@ -18,12 +18,14 @@ test.describe('Card payments with address lookup', () => { test.describe('Card payments with partial avs', () => { test.describe('When fill in a valid the post code', () => { - test('should make a successful card payment', async ({ cardWithAvs }) => { + test('should make a successful card payment', async ({ cardWithAvs, page }) => { await cardWithAvs.goto(URL_MAP.cardWithPartialAvs); await cardWithAvs.typeCardNumber(REGULAR_TEST_CARD); await cardWithAvs.typeExpiryDate(TEST_DATE_VALUE); await cardWithAvs.typeCvc(TEST_CVC_VALUE); await cardWithAvs.billingAddress.fillInPostCode(TEST_POSTCODE); + // wait for the form is valid + await page.waitForFunction(() => globalThis.component.isValid === true); await cardWithAvs.pay(); await cardWithAvs.paymentResult.waitFor({ state: 'visible' }); await expect(cardWithAvs.paymentResult).toContainText(PAYMENT_RESULT.authorised); @@ -58,7 +60,6 @@ test.describe('Card payments with full avs', () => { // wait for the form is valid await page.waitForFunction(() => globalThis.component.isValid === true); await cardWithAvs.pay(); - await cardWithAvs.paymentResult.waitFor({ state: 'visible' }); await expect(cardWithAvs.paymentResult).toContainText(PAYMENT_RESULT.authorised); }); }); diff --git a/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-amex.spec.ts b/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-amex.spec.ts index fc39713e8..d85edc905 100644 --- a/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-amex.spec.ts +++ b/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-amex.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '../../../../fixtures/dropin.fixture'; +import { test } from '@playwright/test'; test.describe('Stored Amex card - cvc required', () => { test('#1 Can fill out the cvc fields in the stored card and make a successful payment', async () => { diff --git a/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-maestro.spec.ts b/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-maestro.spec.ts index c8d965fd2..c9805ce39 100644 --- a/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-maestro.spec.ts +++ b/packages/e2e-playwright/tests/e2e/dropin/storedCard/stored-card-maestro.spec.ts @@ -1,9 +1,44 @@ -import { test } from '@playwright/test'; +import { cardInDropin as test, expect } from '../../../../fixtures/dropin.fixture'; +import { URL_MAP } from '../../../../fixtures/URL_MAP'; +import { PAYMENT_RESULT, TEST_CVC_VALUE, THREEDS2_CHALLENGE_PASSWORD } from '../../../utils/constants'; test.describe('Stored Maestro card - cvc optional', () => { // When user do not fill in the cvc - test('should make a successful payment without the cvc code', async () => {}); + test('should make a successful payment without the cvc code', async ({ dropinWithSession, card }) => { + await dropinWithSession.goto(URL_MAP.dropinWithSession); + await dropinWithSession.selectFirstStoredPaymentMethod('maestro', '0029'); + + await card.cvcInput.waitFor({ state: 'visible' }); + await card.pay({ name: /^Pay/i }); + await card.threeDs2Challenge.fillInPassword(THREEDS2_CHALLENGE_PASSWORD); + await card.threeDs2Challenge.submit(); + + await expect(card.paymentResult).toContainText(PAYMENT_RESULT.success); + }); // When user fills in the cvc - test('should make a successful payment after filling in the correct 3ds challenge password', async () => {}); - test('should decline the payment after filling in the wrong 3ds challenge password', async () => {}); + test('should make a successful payment after filling in the correct 3ds challenge password', async ({ dropinWithSession, card }) => { + await dropinWithSession.goto(URL_MAP.dropinWithSession); + await dropinWithSession.selectFirstStoredPaymentMethod('maestro', '0029'); + + await card.cvcInput.waitFor({ state: 'visible' }); + await card.fillCvc(TEST_CVC_VALUE); + await card.pay({ name: /^Pay/i }); + await card.threeDs2Challenge.fillInPassword(THREEDS2_CHALLENGE_PASSWORD); + await card.threeDs2Challenge.submit(); + + await expect(card.paymentResult).toContainText(PAYMENT_RESULT.success); + }); + + test('should decline the payment after filling in the wrong 3ds challenge password', async ({ dropinWithSession, card }) => { + await dropinWithSession.goto(URL_MAP.dropinWithSession); + await dropinWithSession.selectFirstStoredPaymentMethod('maestro', '0029'); + + await card.cvcInput.waitFor({ state: 'visible' }); + await card.fillCvc(TEST_CVC_VALUE); + await card.pay({ name: /^Pay/i }); + await card.threeDs2Challenge.fillInPassword('dummy'); + await card.threeDs2Challenge.submit(); + + await expect(card.paymentResult).toContainText(PAYMENT_RESULT.fail); + }); });