diff --git a/src/tools/automation-framework/actions/click-action.js b/src/tools/automation-framework/actions/click-action.js index 634f859..c6992a9 100644 --- a/src/tools/automation-framework/actions/click-action.js +++ b/src/tools/automation-framework/actions/click-action.js @@ -57,6 +57,9 @@ class ClickAction extends BaseAction { this.log('warn', `滚动失败,继续尝试点击: ${error.message}`); } + // 模拟人类"准备点击"的短暂停顿 + await this.pauseDelay(); + // 点击(支持人类行为模拟) const humanLike = this.config.humanLike !== false; // 默认使用人类行为 if (humanLike) { @@ -68,6 +71,9 @@ class ClickAction extends BaseAction { this.log('info', '✓ 点击完成'); + // 点击后的自然延迟(等待页面反应) + await this.pauseDelay(); + // 验证点击后的变化(新元素出现 / 旧元素消失) if (this.config.verifyAfter) { await this.verifyAfterClick(this.config.verifyAfter); diff --git a/src/tools/automation-framework/actions/fill-form-action.js b/src/tools/automation-framework/actions/fill-form-action.js index 9a32968..9850c91 100644 --- a/src/tools/automation-framework/actions/fill-form-action.js +++ b/src/tools/automation-framework/actions/fill-form-action.js @@ -16,12 +16,22 @@ class FillFormAction extends BaseAction { this.log('info', `填写表单,共 ${Object.keys(fields).length} 个字段`); // 填写每个字段 - for (const [key, fieldConfig] of Object.entries(fields)) { + const fieldEntries = Object.entries(fields); + for (let i = 0; i < fieldEntries.length; i++) { + const [key, fieldConfig] = fieldEntries[i]; await this.fillField(key, fieldConfig, humanLike); + + // 字段间的停顿(不是最后一个字段时) + if (i < fieldEntries.length - 1) { + await this.pauseDelay(); + } } this.log('info', '✓ 表单填写完成'); + // 模拟人类填写后的思考时间 + await this.thinkDelay(); + return { success: true }; } diff --git a/src/tools/automation-framework/actions/navigate-action.js b/src/tools/automation-framework/actions/navigate-action.js index 2cf91a3..93121f3 100644 --- a/src/tools/automation-framework/actions/navigate-action.js +++ b/src/tools/automation-framework/actions/navigate-action.js @@ -47,13 +47,16 @@ class NavigateAction extends BaseAction { await this.verifyElements(this.config.verifyElements); } - // 可选的等待时间 + this.log('info', `✓ 页面加载完成${attempt > 0 ? ` (尝试 ${attempt + 1} 次)` : ''}`); + + // 模拟人类阅读页面(1-3秒) + await this.readPageDelay(); + + // 可选的额外等待时间 if (this.config.waitAfter) { await new Promise(resolve => setTimeout(resolve, this.config.waitAfter)); } - this.log('info', `✓ 页面加载完成${attempt > 0 ? ` (尝试 ${attempt + 1} 次)` : ''}`); - return { success: true, url: currentUrl }; } catch (error) { diff --git a/src/tools/automation-framework/actions/scroll-action.js b/src/tools/automation-framework/actions/scroll-action.js index 701951b..32e4a49 100644 --- a/src/tools/automation-framework/actions/scroll-action.js +++ b/src/tools/automation-framework/actions/scroll-action.js @@ -58,11 +58,14 @@ class ScrollAction extends BaseAction { throw new Error(`不支持的滚动类型: ${type}`); } - // 等待滚动完成 + // 等待滚动动画完成 await new Promise(resolve => setTimeout(resolve, 500)); this.log('debug', '✓ 滚动完成'); + // 模拟人类滚动后查看内容的停顿 + await this.pauseDelay(); + return { success: true }; } diff --git a/src/tools/automation-framework/configs/sites/windsurf.yaml b/src/tools/automation-framework/configs/sites/windsurf.yaml index 472fbde..0731d50 100644 --- a/src/tools/automation-framework/configs/sites/windsurf.yaml +++ b/src/tools/automation-framework/configs/sites/windsurf.yaml @@ -32,7 +32,6 @@ workflow: # 1.2 填写基本信息 - action: fillForm name: "填写基本信息" - humanLike: true fields: firstName: find: @@ -58,7 +57,6 @@ workflow: selector: - css: 'input[type="checkbox"]' optional: true - waitAfter: 500 # 1.4 点击 Continue - action: click @@ -72,7 +70,6 @@ workflow: appears: - '#password' - 'input[type="password"]' - waitAfter: 2000 # ==================== 步骤 2: 设置密码 ==================== - action: wait @@ -84,7 +81,6 @@ workflow: - action: fillForm name: "设置密码" - humanLike: true fields: password: find: @@ -186,7 +182,6 @@ workflow: # 填写银行卡信息(使用重新生成的卡号) - action: fillForm name: "填写银行卡信息" - humanLike: false fields: cardNumber: find: @@ -226,13 +221,17 @@ workflow: # 填写地址(动态字段) - action: fillForm name: "填写地址" - humanLike: false fields: addressLine1: find: - css: 'input[placeholder*="地址"]' - css: 'input[placeholder*="Address"]' value: "kowloon" + addressLine2: + find: + - css: 'input[placeholder*="Address line 2"]' + - css: 'input[name="billingAddressLine2"]' + value: "Macau" # 滚动到页面底部(确保订阅按钮可见) - action: scroll diff --git a/src/tools/automation-framework/core/base-action.js b/src/tools/automation-framework/core/base-action.js index d8e667b..7022244 100644 --- a/src/tools/automation-framework/core/base-action.js +++ b/src/tools/automation-framework/core/base-action.js @@ -50,6 +50,36 @@ class BaseAction { console.log(`[${level.toUpperCase()}] ${message}`); } } + + /** + * 人类行为延迟工具方法 + */ + + // 随机延迟 + async randomDelay(min, max) { + const delay = min + Math.random() * (max - min); + await new Promise(resolve => setTimeout(resolve, delay)); + } + + // 阅读页面延迟(1-3秒) + async readPageDelay() { + await this.randomDelay(1000, 3000); + } + + // 思考延迟(500-1500ms) + async thinkDelay() { + await this.randomDelay(500, 1500); + } + + // 短暂停顿(200-500ms) + async pauseDelay() { + await this.randomDelay(200, 500); + } + + // 步骤间延迟(1-2秒) + async stepDelay() { + await this.randomDelay(1000, 2000); + } } module.exports = BaseAction;