@wernerthiago/teo
Version:
Test Execution Optimizer
69 lines (51 loc) • 2.68 kB
JavaScript
// Payment processing tests
import { test, expect } from '@playwright/test'
test.describe('Payment Processing', () => {
test.beforeEach(async ({ page }) => {
// Login before each test
await page.goto('/login')
await page.fill('[data-testid="username"]', 'testuser')
await page.fill('[data-testid="password"]', 'password123')
await page.click('[data-testid="login-button"]')
})
test('should process credit card payment successfully', async ({ page }) => {
await page.goto('/checkout')
// Fill payment form
await page.fill('[data-testid="card-number"]', '4111111111111111')
await page.fill('[data-testid="expiry"]', '12/25')
await page.fill('[data-testid="cvv"]', '123')
await page.fill('[data-testid="cardholder-name"]', 'Test User')
await page.click('[data-testid="pay-button"]')
await expect(page.locator('[data-testid="success-message"]')).toBeVisible()
await expect(page.locator('[data-testid="transaction-id"]')).toBeVisible()
})
test('should handle payment validation errors', async ({ page }) => {
await page.goto('/checkout')
// Submit with invalid card
await page.fill('[data-testid="card-number"]', '1234')
await page.click('[data-testid="pay-button"]')
await expect(page.locator('[data-testid="validation-error"]')).toBeVisible()
await expect(page.locator('[data-testid="validation-error"]')).toContainText('Invalid card number')
})
test('should handle payment processing failures', async ({ page }) => {
await page.goto('/checkout')
// Use a card that will be declined
await page.fill('[data-testid="card-number"]', '4000000000000002')
await page.fill('[data-testid="expiry"]', '12/25')
await page.fill('[data-testid="cvv"]', '123')
await page.fill('[data-testid="cardholder-name"]', 'Test User')
await page.click('[data-testid="pay-button"]')
await expect(page.locator('[data-testid="error-message"]')).toBeVisible()
await expect(page.locator('[data-testid="error-message"]')).toContainText('Payment declined')
})
test('should save payment method for future use', async ({ page }) => {
await page.goto('/checkout')
await page.fill('[data-testid="card-number"]', '4111111111111111')
await page.fill('[data-testid="expiry"]', '12/25')
await page.fill('[data-testid="cvv"]', '123')
await page.fill('[data-testid="cardholder-name"]', 'Test User')
await page.check('[data-testid="save-payment-method"]')
await page.click('[data-testid="pay-button"]')
await expect(page.locator('[data-testid="saved-payment-confirmation"]')).toBeVisible()
})
})