|
| 1 | +import { test, expect } from '../fixtures/test-setup.fixture'; |
| 2 | +import { HomePage } from '../page-objects/home-page'; |
| 3 | +import { ProductPage } from '../page-objects/product-page'; |
| 4 | +import { CartDrawer } from '../page-objects/cart-drawer'; |
| 5 | +import { CheckoutPage } from '../page-objects/checkout-page'; |
| 6 | + |
| 7 | +test.describe('Complete Checkout Flow', () => { |
| 8 | + test('should complete a purchase with test payment', async ({ page }) => { |
| 9 | + // Initialize page objects |
| 10 | + const homePage = new HomePage(page); |
| 11 | + const productPage = new ProductPage(page); |
| 12 | + const cartDrawer = new CartDrawer(page); |
| 13 | + const checkoutPage = new CheckoutPage(page); |
| 14 | + |
| 15 | + // Step 1: Visit the home page |
| 16 | + await homePage.goto(); |
| 17 | + |
| 18 | + // Step 2: Add a product to cart from home page |
| 19 | + await homePage.addToCart(); |
| 20 | + |
| 21 | + // Step 3: Open the cart drawer |
| 22 | + await homePage.openCartDrawer(); |
| 23 | + |
| 24 | + // Step 4: Verify cart drawer is open and has items |
| 25 | + await cartDrawer.waitForDrawerOpen(); |
| 26 | + await cartDrawer.verifyItemInCart(); |
| 27 | + |
| 28 | + // Step 5: Proceed to checkout |
| 29 | + await cartDrawer.proceedToCheckout(); |
| 30 | + |
| 31 | + // Step 6: Verify we're on the checkout page |
| 32 | + await expect(page).toHaveURL(/\/checkout/); |
| 33 | + |
| 34 | + // Step 7: Fill in the address form |
| 35 | + await checkoutPage.fillAddressForm({ |
| 36 | + email: 'test@example.com', |
| 37 | + firstName: 'Test', |
| 38 | + lastName: 'User', |
| 39 | + address: '123 Test St', |
| 40 | + city: 'Test City', |
| 41 | + state: 'TX', |
| 42 | + zip: '12345', |
| 43 | + phone: '555-123-4567' |
| 44 | + }); |
| 45 | + |
| 46 | + // Step 8: Select test payment option |
| 47 | + await checkoutPage.selectTestPayment(); |
| 48 | + |
| 49 | + // Step 9: Complete checkout with test payment |
| 50 | + await checkoutPage.completeCheckout(); |
| 51 | + |
| 52 | + // Step 10: Verify successful checkout (this will depend on your app's behavior) |
| 53 | + // For example, you might check for a success message or redirection to a confirmation page |
| 54 | + await expect(page).toHaveURL(/\/confirmation|\/success|\/thank-you/); |
| 55 | + }); |
| 56 | + |
| 57 | + test('should add product from PDP and complete checkout', async ({ page }) => { |
| 58 | + // Initialize page objects |
| 59 | + const productPage = new ProductPage(page); |
| 60 | + const cartDrawer = new CartDrawer(page); |
| 61 | + const checkoutPage = new CheckoutPage(page); |
| 62 | + |
| 63 | + // Step 1: Visit a product detail page (replace with an actual product handle) |
| 64 | + await productPage.goto('sample-product'); |
| 65 | + |
| 66 | + // Step 2: Add the product to cart |
| 67 | + await productPage.addToCart(); |
| 68 | + |
| 69 | + // Step 3: Open the cart drawer |
| 70 | + await productPage.openCartDrawer(); |
| 71 | + |
| 72 | + // Step 4: Verify cart drawer is open and has items |
| 73 | + await cartDrawer.waitForDrawerOpen(); |
| 74 | + await cartDrawer.verifyItemInCart(); |
| 75 | + |
| 76 | + // Step 5: Proceed to checkout |
| 77 | + await cartDrawer.proceedToCheckout(); |
| 78 | + |
| 79 | + // Step 6: Verify we're on the checkout page |
| 80 | + await expect(page).toHaveURL(/\/checkout/); |
| 81 | + |
| 82 | + // Step 7: Fill in the address form |
| 83 | + await checkoutPage.fillAddressForm({ |
| 84 | + email: 'test@example.com', |
| 85 | + firstName: 'Test', |
| 86 | + lastName: 'User', |
| 87 | + address: '123 Test St', |
| 88 | + city: 'Test City', |
| 89 | + state: 'TX', |
| 90 | + zip: '12345', |
| 91 | + phone: '555-123-4567' |
| 92 | + }); |
| 93 | + |
| 94 | + // Step 8: Select test payment option |
| 95 | + await checkoutPage.selectTestPayment(); |
| 96 | + |
| 97 | + // Step 9: Complete checkout with test payment |
| 98 | + await checkoutPage.completeCheckout(); |
| 99 | + |
| 100 | + // Step 10: Verify successful checkout |
| 101 | + await expect(page).toHaveURL(/\/confirmation|\/success|\/thank-you/); |
| 102 | + }); |
| 103 | +}); |
| 104 | + |
0 commit comments