Instructions
- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.
Test info
- Name: app.spec.js >> 账号管理模块 >> TC-015: 禁用功能
- Location: e2e/app.spec.js:78:3
Error details
Error: page.goto: net::ERR_ADDRESS_UNREACHABLE at https://ajy.danclub.cn/
Call log:
- navigating to "https://ajy.danclub.cn/", waiting until "load"
Page snapshot
- generic [ref=e3]:
- generic [ref=e6]:
- heading "This site can’t be reached" [level=1] [ref=e7]
- paragraph [ref=e8]:
- strong [ref=e9]: https://ajy.danclub.cn/
- text: is unreachable.
- generic [ref=e10]: ERR_ADDRESS_UNREACHABLE
- button "Reload" [ref=e13] [cursor=pointer]
Test source
1 | const { test, expect } = require('@playwright/test');
2 |
3 | const BASE_URL = 'https://ajy.danclub.cn';
4 | const TEST_ADMIN = { username: 'admin', password: 'admin123' };
5 |
6 | test.describe('登录模块', () => {
7 | test('TC-001: 正常登录', async ({ page }) => {
8 | await page.goto(BASE_URL);
9 | await page.waitForLoadState('networkidle');
10 | await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
11 | await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
12 | await page.getByRole('button', { name: '登 录' }).click();
13 | await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
14 | });
15 |
16 | test('TC-002: 用户名为空验证', async ({ page }) => {
17 | await page.goto(BASE_URL);
18 | await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
19 | await page.getByRole('button', { name: '登 录' }).click();
20 | await expect(page.getByText('请输入用户名')).toBeVisible();
21 | });
22 |
23 | test('TC-003: 密码为空验证', async ({ page }) => {
24 | await page.goto(BASE_URL);
25 | await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
26 | await page.getByRole('button', { name: '登 录' }).click();
27 | await expect(page.getByText('请输入密码')).toBeVisible();
28 | });
29 |
30 | test('TC-004: 错误账号登录', async ({ page }) => {
31 | await page.goto(BASE_URL);
32 | await page.getByPlaceholder('请输入用户名').fill('wronguser');
33 | await page.getByPlaceholder('请输入密码').fill('wrongpass');
34 | await page.getByRole('button', { name: '登 录' }).click();
35 | await page.waitForTimeout(2000);
36 | await expect(page.getByRole('button', { name: '登 录' })).toBeVisible();
37 | });
38 | });
39 |
40 | test.describe('账号管理模块', () => {
41 | test.beforeEach(async ({ page }) => {
> 42 | await page.goto(BASE_URL);
| ^ Error: page.goto: net::ERR_ADDRESS_UNREACHABLE at https://ajy.danclub.cn/
43 | await page.waitForLoadState('networkidle');
44 | await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
45 | await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
46 | await page.getByRole('button', { name: '登 录' }).click();
47 | await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
48 | });
49 |
50 | test('TC-010: 查看账号管理页面', async ({ page }) => {
51 | await expect(page.locator('.el-table__body')).toBeVisible();
52 | });
53 |
54 | test('TC-011: 账号列表搜索-手机号', async ({ page }) => {
55 | await page.getByPlaceholder('请输入手机号').fill('138');
56 | await page.getByRole('button', { name: '搜索' }).click();
57 | await page.waitForTimeout(1000);
58 | });
59 |
60 | test('TC-012: 账号列表搜索-昵称', async ({ page }) => {
61 | await page.getByPlaceholder('请输入昵称').fill('管理员');
62 | await page.getByRole('button', { name: '搜索' }).click();
63 | await page.waitForTimeout(1000);
64 | });
65 |
66 | test('TC-013: 新增用户按钮存在', async ({ page }) => {
67 | await expect(page.getByRole('button', { name: '新增用户' })).toBeVisible();
68 | });
69 |
70 | test('TC-014: 编辑功能', async ({ page }) => {
71 | const editBtn = page.locator('button:has-text("编辑")').first();
72 | if (await editBtn.isVisible()) {
73 | await editBtn.click();
74 | await page.waitForTimeout(500);
75 | }
76 | });
77 |
78 | test('TC-015: 禁用功能', async ({ page }) => {
79 | const disableBtn = page.locator('button:has-text("禁用")').first();
80 | if (await disableBtn.isVisible()) {
81 | await disableBtn.click();
82 | await page.waitForTimeout(500);
83 | }
84 | });
85 |
86 | test('TC-017: 取消删除', async ({ page }) => {
87 | const deleteBtn = page.locator('button:has-text("删除")').first();
88 | if (await deleteBtn.isVisible()) {
89 | await deleteBtn.click();
90 | await page.waitForTimeout(500);
91 | const cancelBtn = page.getByRole('button', { name: '取消' });
92 | if (await cancelBtn.isVisible()) {
93 | await cancelBtn.click();
94 | }
95 | }
96 | });
97 |
98 | test('TC-017: 重置搜索条件', async ({ page }) => {
99 | await page.getByPlaceholder('请输入手机号').fill('测试');
100 | await page.getByRole('button', { name: '重置' }).click();
101 | await page.waitForTimeout(500);
102 | });
103 | });
104 |
105 | test.describe('穴位管理模块', () => {
106 | test.beforeEach(async ({ page }) => {
107 | await page.goto(BASE_URL);
108 | await page.waitForLoadState('networkidle');
109 | await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username);
110 | await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password);
111 | await page.getByRole('button', { name: '登 录' }).click();
112 | await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 });
113 | });
114 |
115 | test('TC-040: 查看穴位列表', async ({ page }) => {
116 | await expect(page.locator('.el-table__body')).toBeVisible();
117 | });
118 |
119 | test('TC-041: 穴位列表搜索-穴位名称', async ({ page }) => {
120 | await page.goto(`${BASE_URL}/#/acupoint`);
121 | await page.waitForLoadState('networkidle');
122 | await page.getByPlaceholder('请输入穴位名称').first().fill('大椎');
123 | await page.getByRole('button', { name: '查询' }).click();
124 | await page.waitForTimeout(1000);
125 | });
126 |
127 | test('TC-042: 新增按钮存在', async ({ page }) => {
128 | await page.getByRole('button', { name: '新增' }).click();
129 | await page.waitForTimeout(500);
130 | });
131 |
132 | test('TC-043: 查看穴位详情', async ({ page }) => {
133 | const viewBtn = page.locator('button:has-text("查看")').first();
134 | if (await viewBtn.isVisible()) {
135 | await viewBtn.click();
136 | await page.waitForTimeout(500);
137 | }
138 | });
139 |
140 | test('TC-044: 编辑穴位', async ({ page }) => {
141 | const editBtn = page.locator('button:has-text("编辑")').first();
142 | if (await editBtn.isVisible()) {