Files
novalon-manage-system/uat-tests/utils/scenario-runner.ts
T
2026-03-25 09:44:57 +08:00

46 lines
1.2 KiB
TypeScript

import { test, Page } from '@playwright/test';
import { UATHelper } from './uat-helper';
export interface ScenarioConfig {
name: string;
description: string;
priority: 'P0' | 'P1' | 'P2';
setup?: (page: Page) => Promise<void>;
execute: (page: Page, helper: UATHelper) => Promise<void>;
verify?: (page: Page, helper: UATHelper) => Promise<void>;
cleanup?: (page: Page) => Promise<void>;
}
export class ScenarioRunner {
static async runScenario(config: ScenarioConfig) {
test.describe(`${config.name} (${config.priority})`, () => {
test.beforeEach(async ({ page }) => {
if (config.setup) {
await config.setup(page);
}
});
test(config.description, async ({ page }) => {
const helper = new UATHelper(page);
await config.execute(page, helper);
if (config.verify) {
await config.verify(page, helper);
}
});
test.afterEach(async ({ page }) => {
if (config.cleanup) {
await config.cleanup(page);
}
});
});
}
static async runMultipleScenarios(scenarios: ScenarioConfig[]) {
for (const scenario of scenarios) {
await this.runScenario(scenario);
}
}
}