modify playwright ts
This commit is contained in:
parent
752d2991ec
commit
35ed0f72f2
@ -69,7 +69,7 @@ rm -rf "$REPORT_DIR"
|
|||||||
|
|
||||||
# Run Playwright tests with reporters
|
# Run Playwright tests with reporters
|
||||||
set +e # temporarily disable exit-on-error to capture test result
|
set +e # temporarily disable exit-on-error to capture test result
|
||||||
npx playwright test tests/playwright --reporter=list,html
|
BASE_URL=${FRONTEND_URL} npx playwright test tests/playwright --reporter=list,html
|
||||||
TEST_RESULT=$?
|
TEST_RESULT=$?
|
||||||
set -e # re-enable strict mode
|
set -e # re-enable strict mode
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import {test, expect} from "@playwright/test";
|
import {test, expect} from "@playwright/test";
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
test.describe("Alerts 页面功能测试", () => {
|
test.describe("Alerts 页面功能测试", () => {
|
||||||
test.beforeEach(async ({page}) => {
|
test.beforeEach(async ({page}) => {
|
||||||
await page.goto("http://localhost:8080/alerts"); // 根据你实际路由调整
|
await page.goto(`${BASE_URL}/alerts`); // 根据你实际路由调整
|
||||||
});
|
});
|
||||||
|
|
||||||
test("页面加载并显示告警统计", async ({page}) => {
|
test("页面加载并显示告警统计", async ({page}) => {
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
test.describe('Dashboard 页面测试', () => {
|
test.describe('Dashboard 页面测试', () => {
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
// 打开仪表盘页面
|
// 打开仪表盘页面
|
||||||
await page.goto('http://localhost:8080/dashboard', { waitUntil: 'networkidle' });
|
await page.goto(`${BASE_URL}/dashboard`, { waitUntil: 'networkidle' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('应能成功加载页面并显示标题', async ({ page }) => {
|
test('应能成功加载页面并显示标题', async ({ page }) => {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { Page, expect } from '@playwright/test';
|
import { Page, expect } from '@playwright/test';
|
||||||
|
import { BASE_URL } from './utils'
|
||||||
/**
|
/**
|
||||||
* 通用函数:验证页面导航是否正确
|
* 通用函数:验证页面导航是否正确
|
||||||
*/
|
*/
|
||||||
export async function checkPage(page: Page, path: string, title: string) {
|
export async function checkPage(page: Page, path: string, title: string) {
|
||||||
await page.goto('http://localhost:8080/');
|
await page.goto(`${BASE_URL}`);
|
||||||
const menu = page.getByRole('link', { name: title });
|
const menu = page.getByRole('link', { name: title });
|
||||||
await expect(menu).toBeVisible();
|
await expect(menu).toBeVisible();
|
||||||
await menu.click();
|
await menu.click();
|
||||||
|
|||||||
1
src/web/tests/playwright/helpers/utils.ts
Normal file
1
src/web/tests/playwright/helpers/utils.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const BASE_URL = process.env.BASE_URL || "http://localhost:8080";
|
||||||
@ -1,10 +1,11 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import { logsEntries } from './test-entries';
|
import { logsEntries } from './test-entries';
|
||||||
import { testEntryCards } from './helpers/entrycards-helpers';
|
import { testEntryCards } from './helpers/entrycards-helpers';
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
test.describe('Logs Page', () => {
|
test.describe('Logs Page', () => {
|
||||||
test('should render all log cards', async ({ page }) => {
|
test('should render all log cards', async ({ page }) => {
|
||||||
await page.goto('http://localhost:8080m/logs');
|
await page.goto(`${BASE_URL}/logs`);
|
||||||
await expect(page.locator('h2', { hasText: '日志详情' })).toBeVisible();
|
await expect(page.locator('h2', { hasText: '日志详情' })).toBeVisible();
|
||||||
await testEntryCards(page, logsEntries);
|
await testEntryCards(page, logsEntries);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import { metricsEntries } from './test-entries';
|
import { metricsEntries } from './test-entries';
|
||||||
import { testEntryCards } from './helpers/entrycards-helpers';
|
import { testEntryCards } from './helpers/entrycards-helpers';
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
|
|
||||||
test.describe('Metrics Page', () => {
|
test.describe('Metrics Page', () => {
|
||||||
test('should render all metric cards', async ({ page }) => {
|
test('should render all metric cards', async ({ page }) => {
|
||||||
await page.goto('http://localhost:8080/metrics');
|
await page.goto(`${BASE_URL}/metrics`);
|
||||||
await expect(page.locator('h2', { hasText: '指标详情' })).toBeVisible();
|
await expect(page.locator('h2', { hasText: '指标详情' })).toBeVisible();
|
||||||
await testEntryCards(page, metricsEntries);
|
await testEntryCards(page, metricsEntries);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "@playwright/test";
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
test.describe("节点信息页面 NodeInfo", () => {
|
test.describe("节点信息页面 NodeInfo", () => {
|
||||||
// 每次测试前打开目标页面
|
// 每次测试前打开目标页面
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.goto("http://localhost:8080/node");
|
await page.goto(`${BASE_URL}/node`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("页面标题应该正确显示", async ({ page }) => {
|
test("页面标题应该正确显示", async ({ page }) => {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
import { checkPage, noConsoleError } from './helpers/testUtils';
|
import { checkPage, noConsoleError } from './helpers/testUtils';
|
||||||
|
import { BASE_URL } from './helpers/utils'
|
||||||
|
|
||||||
const BASE_URL = 'http://localhost:8080';
|
|
||||||
const pages = [
|
const pages = [
|
||||||
{ path: '/dashboard', title: '仪表盘' },
|
{ path: '/dashboard', title: '仪表盘' },
|
||||||
{ path: '/nodeInfo', title: '节点信息' },
|
{ path: '/nodeInfo', title: '节点信息' },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user