使用playwright内置test

This commit is contained in:
xief 2024-08-02 11:31:51 +08:00
parent 79bb32bc6c
commit b2321c7ee7
10 changed files with 134 additions and 2649 deletions

View File

@ -1,4 +0,0 @@
{
"require":"ts-node/register",
"spec":"./tests/**/*.ts"
}

View File

@ -1,6 +1,6 @@
{
"recommendations": [
"Orta.vscode-jest",
"ms-playwright.playwright",
],
"unwantedRecommendations": []
}

View File

@ -4,7 +4,7 @@
* GIT
* vscode
* nodejs
* vscode-jest插件
* vscode playwright 插件
### 安装依赖
```

View File

@ -1,14 +0,0 @@
const esModules = ['.*\\.mjs$', 'lodash-es'].join('|');
module.exports = {
transform: {
// '^.+\\.vue$': '@vue/vue2-jest', // Update to match your installed version
'^.+\\.(t|j)sx?$': '@swc/jest',
},
extensionsToTreatAsEsm: ['.ts', '.tsx'], // .vue
// testEnvironment: '@happy-dom/jest-environment',
moduleNameMapper: {
// '@/(.*)': '<rootDir>/src/$1',
},
transformIgnorePatterns: [`node_modules/(?!${esModules})`],
};

View File

@ -6,16 +6,14 @@
"scripts": {
"init": "playwright install",
"codegen": "playwright codegen",
"test": "jest"
"test": "playwright test"
},
"author": "",
"license": "ISC",
"packageManager": "pnpm@9.1.1+sha1.09ada6cd05003e0ced25fb716f9fda4063ec2e3b",
"dependencies": {
"@jest/globals": "^29.7.0",
"@swc/core": "^1.7.4",
"@swc/jest": "^0.2.36",
"jest": "^29.7.0",
"@playwright/test": "^1.45.3",
"@types/node": "^22.0.2",
"playwright": "^1.45.3",
"typescript": "^5.5.4"
}

File diff suppressed because one or more lines are too long

42
playwright.config.ts Normal file
View File

@ -0,0 +1,42 @@
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
// Look for test files in the "tests" directory, relative to this configuration file.
testDir: 'tests',
// Run all tests 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 ? 2 : 0,
// Opt out of parallel tests on CI.
// workers: process.env.CI ? 1 : undefined,
// Reporter to use
reporter: 'html',
// use: {
// // Base URL to use in actions like `await page.goto('/')`.
// baseURL: 'http://127.0.0.1:3000',
//
// // Collect trace when retrying the failed test.
// trace: 'on-first-retry',
// },
// Configure projects for major browsers.
// projects: [
// {
// name: 'chromium',
// use: { ...devices['Desktop Chrome'] },
// },
// ],
// 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,
// },
});

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
import { describe, it, expect } from '@jest/globals'
import { test } from '@playwright/test'
import { chromium } from "playwright";
describe("mes登录", function () {
test.describe("mes登录", function () {
it('login', async function () {
test('login', async function () {
const browser = await chromium.launch({
// headless: false
});
@ -32,7 +32,7 @@ describe("mes登录", function () {
await page.waitForTimeout(1000)
let path = await page.evaluateHandle(()=>window.location.hash.substr(1))
expect(await path.jsonValue()).toEqual('/dashboard')
test.expect(await path.jsonValue()).toEqual('/dashboard')
// ---------------------

View File

@ -1,9 +1,9 @@
import { describe, it, expect } from '@jest/globals'
import { test } from '@playwright/test'
import { chromium } from "playwright";
describe('平台', function(){
test.describe('平台', function(){
it('登陆', async function(){
test('登陆', async function(){
const browser = await chromium.launch({
// headless: false
@ -30,7 +30,7 @@ describe('平台', function(){
let path = await page.evaluateHandle(()=>window.location.pathname);
expect(await path.jsonValue()).not.toEqual('/user-login.html')
test.expect(await path.jsonValue()).not.toEqual('/user-login.html')
// ---------------------
await context.close();