import { test as setup, expect } from '@playwright/test'; import { mkdirSync } from 'node:fs'; const STATE = 'e2e/.auth/user.json'; setup('ورود به پنل', async ({ page }) => { const user = process.env.E2E_USER; const password = process.env.E2E_PASSWORD; if (!user || !password) { throw new Error('E2E_USER و E2E_PASSWORD را در e2e/.env تنظیم کنید (نمونه: e2e/.env.example).'); } await page.goto('/login'); await page.locator('#identifier').fill(user); await page.locator('#password').fill(password); await page.getByRole('button', { name: 'ورود', exact: true }).click(); const orgCards = page.locator('.org-card'); await expect(async () => { const onOrgPicker = await orgCards.first().isVisible(); const leftLogin = !page.url().includes('/login'); expect(onOrgPicker || leftLogin).toBe(true); }).toPass({ timeout: 30_000 }); if (await orgCards.first().isVisible()) { const orgName = process.env.E2E_ORG; const card = orgName ? orgCards.filter({ hasText: orgName }).first() : orgCards.first(); await card.click(); } await expect(page).not.toHaveURL(/\/login/, { timeout: 30_000 }); await expect(page.locator('main.content')).toBeVisible(); mkdirSync('e2e/.auth', { recursive: true }); await page.context().storageState({ path: STATE }); });