import { test, expect } from '../../fixtures'; test.describe('سناریوی خرید و سبد خرید (Storefront Checkout Flow)', () => { test('ورود به صفحه اصلی -> رفتن به فروشگاه -> انتخاب محصول -> افزودن به سبد خرید -> تسویه حساب', async ({ page }) => { // 1. ورود به صفحه اصلی await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 45000 }); await expect(page).toHaveTitle(/کنینا|Canina/i); // 2. رفتن به صفحه /shop await page.goto('/shop', { waitUntil: 'domcontentloaded', timeout: 45000 }); await expect(page).toHaveURL(/\/shop/); // بررسی وجود ساختار کاتالوگ فروشگاه و کارت‌های محصول const productCard = page.locator('a[href^="/shop/"]').first(); await expect(productCard).toBeVisible({ timeout: 20000 }); // 3. اعمال فیلتر دسته‌بندی یا دکمه‌های فیلتر const categoryButton = page.locator('button, div').filter({ hasText: /مفاصل|ایمنی|ویتامین|همه|کاتالوگ/i }).first(); if (await categoryButton.isVisible()) { await categoryButton.click(); } // 4. افزودن محصول به سبد خرید از کارت آرشیو یا صفحه محصول const buyButtonOnCard = page.locator('button').filter({ hasText: /خرید/i }).first(); if (await buyButtonOnCard.isVisible()) { await buyButtonOnCard.click(); await page.waitForTimeout(1000); } else { const href = await productCard.getAttribute('href'); if (href) { await page.goto(href, { waitUntil: 'domcontentloaded' }); } else { await productCard.click(); } // افزودن به سبد در صفحه جزئیات محصول const addToCartBtn = page.getByRole('button', { name: /افزودن به سبد خرید/i }).or( page.locator('button').filter({ hasText: /افزودن به سبد/i }) ).first(); await expect(addToCartBtn).toBeVisible({ timeout: 15000 }); await addToCartBtn.click(); await page.waitForTimeout(1000); } // 5. رفتن به صفحه تسویه حساب (Checkout) await page.goto('/checkout', { waitUntil: 'domcontentloaded', timeout: 30000 }); await expect(page).toHaveURL(/\/checkout/); // 6. بررسی لود شدن ساختار تسویه‌حساب (پرداخت یا کاتالوگ یا اطلاعات خریدار) const checkoutPageElement = page.locator('button, div, h2').filter({ hasText: /پرداخت|تسویه‌حساب|سفارش|سبد خرید|کاتالوگ/i }).first(); await expect(checkoutPageElement).toBeVisible({ timeout: 10000 }); }); });