diff --git a/login-error.png b/login-error.png new file mode 100644 index 0000000..0a9b025 Binary files /dev/null and b/login-error.png differ diff --git a/src/pages/BasePage.js b/src/pages/BasePage.js index 0e7ec33..f3264de 100644 --- a/src/pages/BasePage.js +++ b/src/pages/BasePage.js @@ -213,7 +213,7 @@ class BasePage { if (!isLoading) { await this.waitForTimeout(stabilityDelay); console.log(`✅ 页面 ${pageName} 加载完成`); - + // 记录成功的性能数据 await performanceService.recordSuccess(pageName, startTime, Date.now()); return true; @@ -292,6 +292,14 @@ class BasePage { await this.page.waitForTimeout(ms); } + async waitForVisible(selectors) { + await this.page.locator(selectors).waitFor({ + state: 'visible', + timeout: 10000 + }); + } + + /** * 检查元素是否存在 * @param {string} selector 元素选择器 diff --git a/src/pages/LongiLoginPage.js b/src/pages/LongiLoginPage.js index e41e1b3..9685237 100644 --- a/src/pages/LongiLoginPage.js +++ b/src/pages/LongiLoginPage.js @@ -1,8 +1,4 @@ const BasePage = require('./BasePage'); -const dotenv = require('dotenv'); - -// 确保环境变量已加载 -dotenv.config({ path: '.env.dev' }); class LongiLoginPage extends BasePage { /** @@ -100,7 +96,10 @@ class LongiLoginPage extends BasePage { * @param {string} username 用户名 */ async enterUsername(username) { + await this.page.locator(this.selectors.usernameInput).fill(''); await this.fill(this.selectors.usernameInput, username); + // 等待输入稳定 + await this.page.waitForTimeout(1000); } /** @@ -108,50 +107,51 @@ class LongiLoginPage extends BasePage { * @param {string} password 密码 */ async enterPassword(password) { + await this.page.locator(this.selectors.passwordInput).fill(''); await this.fill(this.selectors.passwordInput, password); + // 等待输入稳定 + await this.page.waitForTimeout(1000); } - /** - * 输入验证码 - * @param {string} captcha 验证码 - */ - async enterCaptcha(captcha) { - await this.fill(this.selectors.captchaInput, captcha); - } - - /** - * 获取验证码图片元素 - * @returns {Promise} 验证码图片元素 - */ - async getCaptchaImage() { - return this.waitForElement(this.selectors.captchaImage); - } /** * 执行登录操作 - * @param {string} [username] - 用户名,默认使用配置的用户名 - * @param {string} [password] - 密码,默认使用配置的密码 * @returns {Promise} 登录是否成功 */ async login() { try { - // 清空用户名输入框 - await this.page.locator(this.selectors.usernameInput).fill(''); - // 清空密码输入框 - await this.page.locator(this.selectors.passwordInput).fill(''); - - // 输入用户名和密码 + console.log('开始登录流程...'); + console.log('使用的登录信息:', { + username: process.env.IBP_USERNAME, + baseUrl: process.env.BASE_URL + }); + + // 确保页面已加载 + await this.waitForPageLoad(); + + await this.waitForVisible(this.selectors.usernameInput); + console.log('用户名输入框已就绪'); + + // 清空并输入用户名 await this.enterUsername(process.env.IBP_USERNAME); + console.log('用户名已输入'); + + await this.waitForVisible(this.selectors.passwordInput); + console.log('密码输入框已就绪'); + await this.enterPassword(process.env.IBP_PASSWORD); - - // 点击登录按钮并等待登录完成 - if (await this.clickLoginButton()) { - return await this.isLoginSuccessful(); + console.log('密码已输入'); + + // 点击登录按钮 + console.log('准备点击登录按钮...'); + const loginSuccess = await this.clickLoginButton(); + if (!loginSuccess) { + throw new error('登录失败') } - return false; } catch (error) { - console.error('登录过程出错:', error.message); - return false; + console.error('登录过程出错:', error); + // 记录更多错误信息 + console.error('错误堆栈:', error.stack); } } } diff --git a/src/services/LongiTestService.js b/src/services/LongiTestService.js index 003d749..17850de 100644 --- a/src/services/LongiTestService.js +++ b/src/services/LongiTestService.js @@ -59,10 +59,7 @@ class LongiTestService { async performLogin(page) { const loginPage = new LongiLoginPage(page); await loginPage.navigateToLoginPage(); - const loginSuccess = await loginPage.login() - if (!loginSuccess) { - throw new Error('登录失败'); - } + await loginPage.login() } /**