diff --git a/novalon-manage-web/e2e/role-based-tests/scenarios/authentication/login-flow.spec.ts b/novalon-manage-web/e2e/role-based-tests/scenarios/authentication/login-flow.spec.ts index 15dd161..dd7d34c 100644 --- a/novalon-manage-web/e2e/role-based-tests/scenarios/authentication/login-flow.spec.ts +++ b/novalon-manage-web/e2e/role-based-tests/scenarios/authentication/login-flow.spec.ts @@ -34,10 +34,15 @@ test.describe('登录流程测试', () => { await page.fill('input[placeholder*="用户名"]', 'admin'); await page.fill('input[placeholder*="密码"]', 'wrongpassword'); - await page.click('button:has-text("登录")'); - const errorMessage = page.locator('.el-message--error'); - await expect(errorMessage).toBeVisible({ timeout: 5000 }); + await Promise.all([ + page.waitForResponse(resp => resp.url().includes('/auth/login') && resp.status() === 401), + page.click('button:has-text("登录")') + ]); + + const errorMessage = page.locator('.el-message'); + await expect(errorMessage).toBeVisible({ timeout: 10000 }); + await expect(errorMessage).toContainText(/用户名或密码错误|登录失败/i); await expect(page).toHaveURL(/\/login/); }); diff --git a/novalon-manage-web/src/utils/request.ts b/novalon-manage-web/src/utils/request.ts index 8d38e7d..e2b8511 100644 --- a/novalon-manage-web/src/utils/request.ts +++ b/novalon-manage-web/src/utils/request.ts @@ -47,7 +47,9 @@ request.interceptors.response.use( (error) => { if (error.response?.status === 401) { localStorage.removeItem('token') - window.location.href = '/login' + if (!window.location.pathname.includes('/login')) { + window.location.href = '/login' + } } return Promise.reject(error) }