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/playwright.config.js
LingandRX d44f457d86 test(boss_cashier): 优化挂单测试流程
- 移除不必要的挂单数量记录步骤
- 简化挂单流程,每个员工只挂单一次
- 使用 expect.soft 进行软断言,提高测试稳定性
- 优化员工选择和挂单校验的代码结构
2025-03-23 11:54:08 +08:00

139 lines
4.6 KiB
JavaScript

// @ts-check
const { defineConfig, devices } = require('@playwright/test');
import dotenv from "dotenv";
import path from 'path';
import { firstAccount } from './tests/common/auth';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
require('dotenv').config({ path: path.resolve(__dirname, '.env') });
dotenv.config({
path: path.resolve(
__dirname,
".env" + `${process.env.NODE_ENV ? "." + process.env.NODE_ENV : ""}`
),
});
const firstAuthFile = firstAccount.authFile;
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
name: '美管加自动测试框架',
timeout: 10 * 60 * 1000,
globalTimeout: 600 * 60 * 1000,
expect: {
timeout: 30 * 1000,
toPass: {
timeout: 30 * 1000,
},
},
testDir: './tests/',
snapshotPathTemplate: '{testDir}/imgs/__screenshots__/{testFilePath}/{arg}{ext}',
/* Run tests in files in parallel */
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 ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 2,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
// reporter: [['html'], ['list'], ['./my-awesome-reporter.ts']],
reporter: [['html'], ['list']],
// reporter: './my-awesome-reporter.ts',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
actionTimeout: 30 * 1000,
navigationTimeout: 60 * 1000,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
hasTouch: true,
trace: 'on',
screenshot: 'only-on-failure',
timezoneId: 'Asia/Shanghai',
locale: 'zh-CN',
geolocation: { longitude: 114.24, latitude: 22.73 },
permissions: ['geolocation'],
extraHTTPHeaders: {
'Accept-Language': 'zh-CN,zh;q=0.9',
},
video: {
mode: 'retain-on-failure',
size: { width: 640, height: 480 },
},
},
/* Configure projects for major browsers */
projects: [
{
name: '总部管理员鉴权',
testMatch: /.*boss_auth\.setup\.ts/,
use: { baseURL: process.env.BASE_URL },
},
{
name: '门店员工鉴权',
testMatch: /.*staff_auth\.setup\.ts/,
use: { baseURL: process.env.BASE_URL },
},
{
name: '慧来客touch(管理员身份) - Desktop Chrome',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASE_URL,
storageState: firstAuthFile,
// viewport: { width: 1280, height: 720 },
isMobile: true,
},
testMatch: /.*boss_.*\.spec\.ts/,
dependencies: ['总部管理员鉴权'],
},
{
name: '慧来客touch(管理员身份) - Desktop Safari',
use: {
...devices['Desktop Safari'],
baseURL: process.env.BASE_URL,
storageState: firstAuthFile,
// viewport: { width: 1280, height: 720 },
isMobile: true,
},
testMatch: /.*boss_.*\.spec\.ts/,
dependencies: ['总部管理员鉴权'],
},
{
name: '慧来客touch(门店员工身份) - Desktop Chrome',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASE_URL,
// viewport: { width: 1280, height: 720 },
isMobile: false,
},
testMatch: /.*staff_.*\.spec\.ts/,
dependencies: ['门店员工鉴权'],
},
{
name: '慧来客touch(门店员工身份) - Desktop Safari',
use: {
...devices['Desktop Safari'],
baseURL: process.env.BASE_URL,
// viewport: { width: 1280, height: 720 },
isMobile: false,
},
testMatch: /.*staff_.*\.spec\.ts/,
dependencies: ['门店员工鉴权'],
},
],
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});