UNPKG

external-services-automation

Version:

External services automation library for Playwright and Cucumber

59 lines (58 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdatePaymentMethodPage = void 0; const test_1 = require("@playwright/test"); class UpdatePaymentMethodPage { constructor(page) { this.page = page; this.pageContainer = page.locator('[data-testid="page-container-main"]').first(); this.stripeIframe = page.locator('iframe[src*="stripe.com"]').first(); this.continueButton = page.locator('button[data-testid="confirm"]'); } async clickContinue() { await this.continueButton.click(); } async isOnUpdatePaymentMethodPage() { await (0, test_1.expect)(this.pageContainer).toBeVisible(); await (0, test_1.expect)(this.stripeIframe).toBeVisible(); await (0, test_1.expect)(this.continueButton).toBeVisible(); } async fillCardInformation() { const cardNumber = '4242424242424242'; const expirationDate = '12/34'; const securityCode = '567'; const zipCode = '12345'; try { await this.stripeIframe.waitFor({ state: 'visible' }); // Get the iframe element and switch to it const iframeElement = await this.stripeIframe.elementHandle(); if (!iframeElement) { throw new Error('Stripe iframe not found'); } // Switch to the iframe context const iframePage = await iframeElement.contentFrame(); if (!iframePage) { throw new Error('Could not access iframe content'); } const cardNumberField = iframePage.locator('input[name="number"]'); const expirationDateField = iframePage.locator('input[name="expiry"]'); const securityCodeField = iframePage.locator('input[name="cvc"]'); const zipCodeField = iframePage.locator('input[name="postalCode"]'); await cardNumberField.fill(cardNumber); await expirationDateField.fill(expirationDate); await securityCodeField.fill(securityCode); if (await zipCodeField.isVisible()) { await zipCodeField.fill(zipCode); } await this.page.bringToFront(); } catch (error) { console.error('Error filling card information:', error); if (!cardNumber || !expirationDate || !securityCode) { throw new Error(`Cannot use keyboard fallback - missing data: cardNumber=${cardNumber}, expirationDate=${expirationDate}, securityCode=${securityCode}`); } throw error; } } } exports.UpdatePaymentMethodPage = UpdatePaymentMethodPage;