4 Commits

Author SHA1 Message Date
xief
6dec5b6e82 更新依赖库 2025-05-08 14:51:31 +08:00
xief
b2194e5950 拆单测试 2025-05-08 14:47:15 +08:00
xief
a1fc1b2863 更新ignore 2024-08-02 11:37:44 +08:00
xief
b2321c7ee7 使用playwright内置test 2024-08-02 11:31:51 +08:00
11 changed files with 148 additions and 2673 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,7 @@
node_modules/
coverage/
*.log
# tests
test-results/
playwright-report/

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,17 +6,15 @@
"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": "^1.45.3",
"typescript": "^5.5.4"
"@playwright/test": "^1.52.0",
"@types/node": "^22.15.16",
"playwright": "^1.52.0",
"typescript": "^5.8.3"
}
}

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,
// },
});

2669
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

54
tests/cad/cd.test.ts Normal file
View File

@@ -0,0 +1,54 @@
import { test, expect } from '@playwright/test';
test('webcad-cd', async ({ page }) => {
await page.goto('https://t.cfcad.cn/');
await page.getByPlaceholder('请输入您的账号').click();
await page.getByPlaceholder('请输入您的账号').fill('zc3');
await page.getByPlaceholder('请输入您的账号').press('Tab');
await page.getByPlaceholder('请输入您的密码').fill('123456');
await page.getByRole('button', { name: '登录' }).click();
await page.getByRole('button', { name: '开始设计>>' }).click();
await page.getByRole('listitem', { name: '左右侧板 LEFTRIGHTBOARD' }).getByRole('img').click();
await page.getByRole('button', { name: '确定' }).click();
await page.locator('canvas').nth(1).click({
position: {
x: 483,
y: 381
}
});
await page.getByText('顶底板').click();
await page.getByRole('button', { name: '确定' }).click();
await page.locator('canvas').nth(1).click({
position: {
x: 520,
y: 377
}
});
await page.getByPlaceholder('请输入命令:').click();
await page.getByPlaceholder('请输入命令:').fill('cd');
await page.getByPlaceholder('请输入命令:').press('Enter');
await page.locator('canvas').nth(1).click({
position: {
x: 826,
y: 447
}
});
await page.locator('canvas').nth(1).click({
position: {
x: 402,
y: 57
}
});
await page.locator('body').press('Enter');
await page.frameLocator('iframe').getByRole('cell', { name: '|||' }).click();
await page.frameLocator('iframe').locator('td:nth-child(3) > .cell').first().dblclick();
await page.frameLocator('iframe').getByRole('button', { name: '下一步' }).click();
await page.frameLocator('iframe').getByPlaceholder('请输入内容').nth(1).click();
await page.frameLocator('iframe').getByPlaceholder('请输入内容').nth(1).fill('11');
await page.frameLocator('iframe').getByPlaceholder('请输入内容').nth(2).click();
await page.frameLocator('iframe').getByPlaceholder('请输入内容').nth(2).fill('2222');
await page.frameLocator('iframe').locator('#app').click();
const page1Promise = page.waitForEvent('popup');
await page.frameLocator('iframe').getByRole('button', { name: '保存' }).click();
const page1 = await page1Promise;
});

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();