elearning/frontend_management/playwright.config.ts
Missez 9bc24fbe8a
All checks were successful
Build and Deploy Frontend Management to Dev Server / Build Frontend Management Docker Image (push) Successful in 1m17s
Build and Deploy Frontend Management to Dev Server / Deploy E-learning Frontend Management to Dev Server (push) Successful in 8s
Build and Deploy Frontend Management to Dev Server / Notify Deployment Status (push) Successful in 2s
feat: Establish Playwright testing infrastructure with initial tests for authentication, admin, and instructor modules, and fix instructor video and quiz lesson management pages.
2026-03-02 15:48:47 +07:00

93 lines
3 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
import { fileURLToPath } from 'url';
import path from 'path';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
timeout: 60000, // timeout ต่อ test (ms)
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
// workers: process.env.CI ? 1 : undefined,
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: 'http://localhost:3000/',// ปรับเป็น URL ที่ทดสอบ
headless: false, // false = เห็น browser ขณะรัน
screenshot: 'only-on-failure', // เก็บ screenshot เมื่อ fail
trace: 'retain-on-failure', // เก็บ trace เพื่อดีบักเมื่อ fail
// launchOptions: {
// slowMo: 1000,
// }, // ช้าลง 10 วินาที
},
/* ──── Setup Projects: login ครั้งเดียว แล้ว save cookies ──── */
projects: [
{
name: 'admin-setup',
testMatch: /admin\.setup\.ts/,
testDir: './tests',
},
{
name: 'instructor-setup',
testMatch: /instructor\.setup\.ts/,
testDir: './tests',
},
/* ──── Auth tests: ไม่ต้อง login ก่อน ──── */
{
name: 'auth-tests',
testDir: './tests/auth',
use: { ...devices['Desktop Chrome'] },
},
/* ──── Admin tests: ใช้ cookies จาก admin-setup ──── */
{
name: 'admin-tests',
testDir: './tests/admin',
use: {
...devices['Desktop Chrome'],
storageState: path.resolve(__dirname, 'tests/.auth/admin.json'),
},
dependencies: ['admin-setup'],
},
/* ──── Instructor tests: ใช้ cookies จาก instructor-setup ──── */
{
name: 'instructor-tests',
testDir: './tests/instructor',
use: {
...devices['Desktop Chrome'],
storageState: path.resolve(__dirname, 'tests/.auth/instructor.json'),
},
dependencies: ['instructor-setup'],
},
],
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});