Skip to content

Commit 0c7faf9

Browse files
committed
Add 3ds credit card automated tests
1 parent 1276822 commit 0c7faf9

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

tests/fixtures/payment-methods.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ export const PAYMENT_METHODS: Record<string, PaymentMethod> = {
4949
classic: 'input[name="payment_method"][value="monei"]',
5050
block: '.wc-block-components-radio-control__input[value="monei"]'
5151
},
52-
presetCredentials: 'success'
52+
presetCredentials: 'threeDSecure'
53+
},
54+
CREDIT_CARD_FAIL: {
55+
id: 'monei',
56+
name: 'Credit Card (Hosted)',
57+
className: 'wc-monei-credit-card-hosted-payment-method',
58+
isApplicableToSubscription: true,
59+
paymentProcessFunction: 'processCreditCardHostedPayment',
60+
isHostedPayment: true,
61+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK'], // Example countries
62+
selector: {
63+
classic: 'input[name="payment_method"][value="monei"]',
64+
block: '.wc-block-components-radio-control__input[value="monei"]'
65+
},
66+
presetCredentials: 'fail'
5367
},
5468

5569
// Bizum

tests/fixtures/test-configurations.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ export function generateTestConfigurations(options: {
7070
export const TEST_CONFIGURATIONS = {
7171
// Quick smoke test
7272
QUICK: generateTestConfigurations({
73-
paymentMethods: [PAYMENT_METHODS.CREDIT_CARD_SUCCESS],
73+
paymentMethods: [PAYMENT_METHODS.CREDIT_CARD_FAIL],
7474
checkoutTypes: [CHECKOUT_TYPES.CLASSIC],
7575
productTypes: [PRODUCT_TYPES.SIMPLE],
7676
userStates: [USER_STATES.GUEST],
77-
userTypes: [USER_TYPES.ES_USER]
77+
userTypes: [USER_TYPES.ES_USER],
78+
expectSuccess: false
7879
}),
7980
//PayPal Tests
8081
PAYPAL_TESTS: [
@@ -139,9 +140,9 @@ export const TEST_CONFIGURATIONS = {
139140

140141
// Credit card comprehensive tests
141142
CREDIT_CARD_TESTS: generateTestConfigurations({
142-
paymentMethods: [PAYMENT_METHODS.CREDIT_CARD_SUCCESS, PAYMENT_METHODS.CREDIT_CARD_HOSTED],
143+
paymentMethods: [PAYMENT_METHODS.CREDIT_CARD_HOSTED],
143144
checkoutTypes: Object.values(CHECKOUT_TYPES),
144-
productTypes: [PRODUCT_TYPES.SIMPLE, PRODUCT_TYPES.VARIABLE],
145+
productTypes: [PRODUCT_TYPES.SIMPLE],
145146
userStates: Object.values(USER_STATES),
146147
userTypes: Object.values(USER_TYPES)
147148
}),

tests/helpers/payment-processors/credit-card-processor.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export class CreditCardProcessor extends BasePaymentProcessor {
3636
await frameLocator.getByTestId(this.cardCvcInput).fill(cardDetails.cvc);
3737

3838
await this.page.getByTestId(this.submitButton).click();
39+
if (preset === 'threeDSecure' || preset === 'fail') {
40+
await this.complete3DSecure(preset);
41+
}
3942
} else {
4043
const frameLocator = this.page.frameLocator('iframe[name^="__zoid__monei_card_input__"]');
4144

@@ -46,7 +49,7 @@ export class CreditCardProcessor extends BasePaymentProcessor {
4649
await frameLocator.getByTestId(this.cardCvcInput).fill(cardDetails.cvc);
4750
await this.clickWooSubmitButton()
4851
if (preset === 'threeDSecure') {
49-
await this.complete3DSecure();
52+
await this.complete3DSecure(preset);
5053
}
5154
}
5255
}
@@ -68,19 +71,12 @@ export class CreditCardProcessor extends BasePaymentProcessor {
6871
return this.page.$$eval(errorSelector, errors => errors.map(e => e.textContent?.trim()));
6972
}
7073

71-
async complete3DSecure() {
72-
// Wait for 3D Secure iframe to load
73-
await this.page.waitForSelector('iframe[name^="monei-3ds-"]');
74-
75-
// Switch to 3D Secure iframe
76-
// @ts-ignore
77-
const frame = this.page.frame({ name: /monei-3ds-/ });
78-
if (!frame) throw new Error('3D Secure iframe not found');
79-
80-
// Complete 3D Secure verification (this may vary depending on the bank's 3D Secure implementation)
81-
await frame.waitForSelector('#password');
82-
await frame.fill('#password', '1234');
83-
await frame.click('#submit-button');
74+
async complete3DSecure(status) {
75+
if (status === 'threeDSecure') {
76+
await this.page.getByTestId('complete-button').click();
77+
} else if (status === 'fail') {
78+
await this.page.getByTestId('fail-button').click();
79+
}
8480

8581
// Wait for redirection back to the order received page
8682
await this.page.waitForNavigation({ waitUntil: 'networkidle' });

tests/specs/payment-gateway-matrix.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getPaymentProcessor } from '../helpers/payment-processors';
66
import { OrderVerification } from '../verification/order-verification';
77
import {CartPage} from "../pages/cart-page";
88

9-
const configName = process.env.TEST_CONFIG || 'PAYPAL_TESTS';
9+
const configName = process.env.TEST_CONFIG || 'QUICK';
1010
const configurations = TEST_CONFIGURATIONS[configName];
1111

1212
// Each configuration is a complete test case with all the properties needed for the test
@@ -25,14 +25,14 @@ test.describe('Payment Gateway Matrix Tests', () => {
2525
const checkoutPage = new CheckoutPage(page, checkoutType);
2626
const cartHelper = new CartPage(page);
2727
const paymentProcessor = getPaymentProcessor(paymentMethod.id, page);
28+
//check if is credit card and if is hosted then change option to have the proper checkout option
2829
const orderVerification = new OrderVerification(page);
2930

3031
await cartHelper.addProductToCart(productType);
3132
await checkoutPage.goToCheckout(checkoutType.isBlockCheckout);
3233
await checkoutPage.fillBillingDetails(userType);
3334
const selector = paymentMethod.selector[checkoutType.isBlockCheckout? 'block' : 'classic'];
3435
await page.click(selector);
35-
3636
await paymentProcessor.processPayment(paymentMethod.isHostedPayment, paymentMethod.presetCredentials);
3737

3838
if (expectSuccess) {

tests/verification/order-verification.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ export class OrderVerification {
1919
}
2020

2121
async verifyFailedPayment() {
22-
await this.page.waitForSelector(this.failureSelector, { timeout: 30000 });
22+
// Check that we arrived at the pay for order page
23+
const isFailureVisible = await this.page.isVisible(this.failureSelector);
24+
expect(isFailureVisible).toBeTruthy();
2325

24-
const errorMessage = await this.page.textContent(this.failureSelector);
25-
expect(errorMessage).toBeTruthy();
26+
// Check that at least one payment gateway is visible
27+
const isPaymentMethodVisible = await this.page.isVisible('input[name="payment_method"]') ||
28+
await this.page.isVisible('.wc-block-components-radio-control__input[name="radio-control-payment-method"]');
29+
30+
expect(isPaymentMethodVisible).toBeTruthy();
2631
}
2732

2833
private async getOrderNumber(): Promise<string> {

0 commit comments

Comments
 (0)