This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
hlk_autotest/tests/fixtures/merchantFixture.ts
LingandRX 6517e4192c feat: 初始化慧来客自动化测试项目
- 添加项目配置文件和环境变量设置
- 创建测试用例目录结构和命名规范
- 实现基础测试 fixture 和页面对象模型
- 添加示例测试用例和数据生成器
- 配置 playwright 和 gitignore 文件
2024-12-22 19:18:27 +08:00

53 lines
1.5 KiB
TypeScript

import { test as base } from '@/fixtures/boss_common';
import { BrowserContext, Page, TestInfo } from '@playwright/test';
import path from 'path';
import fs from 'fs';
// 定义商户数据类型
type Merchant = {
id: string;
name: string;
storageState: string;
};
// 二维码能够解析出url
const authDirPath = path.resolve(__dirname, '../../.auth');
if (!fs.existsSync(authDirPath)) {
fs.mkdirSync(authDirPath, { recursive: true });
}
const merchants: Merchant[] = [
{
id: '14920',
name: '商户 1',
storageState: path.resolve(authDirPath, 'admin_first.json'),
},
{
id: '14983',
name: '商户 2',
storageState: path.resolve(authDirPath, 'admin_second.json'),
},
];
export const test = base.extend<{
page: Page;
}>({
page: async ({ browser, baseURL }, use, workerInfo: TestInfo) => {
// 根据 workerIndex 从商户池中获取对应商户
const selectedMerchant = merchants[workerInfo.workerIndex % merchants.length];
// const selectedMerchant = merchants[1];
const context: BrowserContext = await browser.newContext({
storageState: selectedMerchant.storageState,
});
const page: Page = await context.newPage();
console.log(`使用的商户: ${selectedMerchant.name}`);
await page.goto(baseURL || '');
// 使用商户信息进行测试
await use(page);
await page.close();
await context.close();
},
});
export { expect } from './boss_common';