1+ import { Page } from '@playwright/test' ;
2+ import { BasePaymentProcessor } from "./base-payment-processor" ;
3+ import { PAYMENT_TEST_DATA } from "../../fixtures/payment-test-data" ;
4+
5+ export class BizumProcessor extends BasePaymentProcessor {
6+
7+ // Locators
8+ readonly phoneInput = 'bizum-phone-input' ;
9+ readonly bizumButton = 'bizum-button' ;
10+ readonly submitButton = 'bizum-pay-button' ;
11+ readonly confirmButton = '#bizum-confirm' ;
12+ readonly successMessage = '.bizum-success-message' ;
13+ readonly errorMessage = '.bizum-error-message' ;
14+
15+ constructor ( page : Page ) {
16+ super ( page ) ;
17+ }
18+
19+ /**
20+ * Feature: Bizum payment
21+ * Scenario: User can pay with Bizum
22+ * Given the user has been redirected to Bizum
23+ * When the user enters their phone number
24+ * And confirms the payment
25+ * Then the payment should be processed successfully
26+ */
27+ async processPayment ( expectSuccess , preset : string = 'success' ) {
28+ const bizumDetails = PAYMENT_TEST_DATA . bizum [ preset ] ;
29+
30+ const buttonLocator = this . page . frameLocator ( 'iframe[name^="__zoid__monei_bizum_button"]' ) ;
31+ await buttonLocator . getByTestId ( this . phoneInput ) . click ( ) ;
32+ const frameLocator = this . page . frameLocator ( 'iframe[name^="__zoid__monei_bizum__"]' ) ;
33+ await frameLocator . getByTestId ( this . phoneInput ) . fill ( bizumDetails . phoneNumber ) ;
34+ await frameLocator . getByTestId ( this . submitButton ) . click ( ) ;
35+
36+ await this . page . waitForTimeout ( 15000 ) ;
37+ }
38+
39+ /**
40+ * Feature: Bizum payment error handling
41+ * Scenario: User enters invalid phone number
42+ * Given the user is on the Bizum payment page
43+ * When the user enters an invalid phone number
44+ * Then an error message should be displayed
45+ */
46+ async handleInvalidPhoneNumber ( invalidPhone : string ) {
47+ await this . page . fill ( this . phoneInput , invalidPhone ) ;
48+ await this . page . click ( this . submitButton ) ;
49+
50+ await this . page . waitForSelector ( this . errorMessage ) ;
51+ return this . page . textContent ( this . errorMessage ) ;
52+ }
53+
54+ /**
55+ * Feature: Bizum payment cancellation
56+ * Scenario: User cancels Bizum payment
57+ * Given the user is on the Bizum payment confirmation page
58+ * When the user clicks the cancel button
59+ * Then they should be redirected back to the merchant site
60+ */
61+ async cancelPayment ( ) {
62+ const cancelButtonSelector = '#bizum-cancel' ;
63+ await this . page . waitForSelector ( cancelButtonSelector ) ;
64+ await this . page . click ( cancelButtonSelector ) ;
65+ await this . page . waitForNavigation ( { waitUntil : 'networkidle' } ) ;
66+ }
67+
68+ /**
69+ * Feature: Bizum payment timeout
70+ * Scenario: Bizum payment times out
71+ * Given the user has initiated a Bizum payment
72+ * When the payment is not confirmed within the timeout period
73+ * Then an error message should be displayed
74+ */
75+ async handlePaymentTimeout ( ) {
76+ const timeoutErrorSelector = '.bizum-timeout-error' ;
77+ await this . page . waitForSelector ( timeoutErrorSelector , { timeout : 120000 } ) ; // 2 minutes timeout
78+ return this . page . textContent ( timeoutErrorSelector ) ;
79+ }
80+ }
0 commit comments