Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 430274dbf9 | |||
| 0157fde0f1 | |||
| aa9bf262fe |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -2,6 +2,29 @@
|
|||||||
|
|
||||||
本文件对应技能市场 **「更新日志」** Tab。
|
本文件对应技能市场 **「更新日志」** Tab。
|
||||||
|
|
||||||
|
## 1.1.26
|
||||||
|
|
||||||
|
- **按用户最新要求改回「自动点登录」行为**:「到了 /industries/campus/smartcampus/login 整个页面,有账号和密码可用直接点登录跳转」
|
||||||
|
- `_wait_for_login_inputs_filled` 改回 v1.1.21 行为:input 都有值 → 自动点 Sign in / 登录按钮 → return True
|
||||||
|
- 与 `_try_auto_sign_in` 行为统一:登录页 = 「有数据自动点」/ 「无数据等用户输入」
|
||||||
|
- 测试替换:`wait_login_inputs_filled_no_auto_click_v1_24` → `wait_login_inputs_filled_auto_click_v1_26`,合计 63/63
|
||||||
|
|
||||||
|
## 1.1.25
|
||||||
|
|
||||||
|
- **按用户要求修正登录页等待逻辑**:
|
||||||
|
- 有数据(账号密码已存在)→ 自动点登录按钮(`_try_auto_sign_in`)
|
||||||
|
- **无数据 → 等待用户输入完成(最多 180 秒)→ 等 URL 跳离登录页**(按钮交给用户自己点,脚本不抢按钮)
|
||||||
|
- `_wait_for_login_inputs_filled` 重写为「**等待模式**」:不再自动点 Sign in / 登录按钮;只轮询 input 值 + URL,每 15 秒提示「请点登录按钮」或「等待输入」
|
||||||
|
- 根域登录 + SPA 二级登录页统一使用同一套行为
|
||||||
|
- 新增测试 `wait_login_inputs_filled_no_auto_click_v1_24` 验证不抢按钮,合计 63/63
|
||||||
|
|
||||||
|
## 1.1.24
|
||||||
|
|
||||||
|
- **修复 `/industries/campus/smartcampus/login` 等待过久问题**:sandbox 在用户首次登录后可能把人踢回 SPA 二级登录页(按钮中文「登录」),之前根域自动登录代码不识别这个 URL + 中文按钮,导致脚本卡死等用户输入
|
||||||
|
- `_try_auto_sign_in` 扩展为通用版本:支持 `#jc-user` / `input[type='tel']` / `input[autocomplete='username']` 多种 user input selector;按钮文本按优先级匹配 `Sign in` > `登录` > `Login` > `signin` > `submit`
|
||||||
|
- `collect_all` 登录后新增步骤 4.5:等 URL 稳定到 `/app/` 或 `/select` 后,若发现 URL 仍含 `/login` / `/signin`(落在 SPA 二级登录页),自动重走一次 `_try_auto_sign_in` → 再等 URL 跳到 `/app/` 或 `/select`
|
||||||
|
- 新增 4 个测试覆盖 `_try_auto_sign_in`(SPA 中文按钮 / 根域英文按钮 / input 空 / selector 超时),合计 58/58
|
||||||
|
|
||||||
## 1.1.23
|
## 1.1.23
|
||||||
|
|
||||||
- **修复登录后跳 /app/home 的流程**:
|
- **修复登录后跳 /app/home 的流程**:
|
||||||
|
|||||||
2
SKILL.md
2
SKILL.md
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: 合同到期智能预警与续聘辅助
|
name: 合同到期智能预警与续聘辅助
|
||||||
description: "当用户说要扫描即将到期的合同、查 90/60/30 天预警名单、给某位教师生成续聘任务书、下发单位版续聘清单、从 SmartCampus HR 平台抓合同数据、解析续聘材料 PDF/Word、查看本月合同到期人员清单时,加载本技能。支持定时扫描(每日凌晨)+ 数据管理 + Agent 三入口,覆盖合同到期智能预警与续聘辅助全流程。"
|
description: "当用户说要扫描即将到期的合同、查 90/60/30 天预警名单、给某位教师生成续聘任务书、下发单位版续聘清单、从 SmartCampus HR 平台抓合同数据、解析续聘材料 PDF/Word、查看本月合同到期人员清单时,加载本技能。支持定时扫描(每日凌晨)+ 数据管理 + Agent 三入口,覆盖合同到期智能预警与续聘辅助全流程。"
|
||||||
version: 1.1.23
|
version: 1.1.26
|
||||||
author: 深圳匠厂科技有限公司
|
author: 深圳匠厂科技有限公司
|
||||||
metadata:
|
metadata:
|
||||||
openclaw:
|
openclaw:
|
||||||
|
|||||||
@@ -180,19 +180,27 @@ def _is_spa_routed(page) -> bool:
|
|||||||
def _try_auto_sign_in(page, wait_input_sec: int = 2) -> bool:
|
def _try_auto_sign_in(page, wait_input_sec: int = 2) -> bool:
|
||||||
"""v1.1.21:检测登录页 demo/123456 是否已预填,有则自动点 Sign in。
|
"""v1.1.21:检测登录页 demo/123456 是否已预填,有则自动点 Sign in。
|
||||||
|
|
||||||
适用场景:sandbox root 登录页(https://sandbox.jc2009.com/)
|
v1.1.24:扩展到支持 SPA 二级登录页(/industries/campus/smartcampus/login),
|
||||||
默认有 demo + 123456 预填在 #jc-user / #jc-pass,脚本无需 fill 直接点。
|
按钮文本可能是中文「登录」而非英文「Sign in」。
|
||||||
|
|
||||||
|
适用场景:
|
||||||
|
- 根域登录页(https://sandbox.jc2009.com/):按钮「Sign in」
|
||||||
|
- SPA 二级登录页(/industries/campus/smartcampus/login):按钮「登录」
|
||||||
|
默认有 demo/123456(或 18677308191 等真实账号)预填在 input。
|
||||||
|
|
||||||
行为:
|
行为:
|
||||||
1. 等 #jc-user 出现,最长 wait_input_sec 秒(默认 2s)
|
1. 等 input 出现,最长 wait_input_sec 秒(默认 2s)
|
||||||
2. 检查 #jc-user 和 #jc-pass 是否都有值
|
2. 检查 input 是否都有值
|
||||||
3. 有值 → 点 Sign in → return True
|
3. 有值 → 点 Sign in / 登录 → return True
|
||||||
4. 无值 → return False(交给 _wait_for_manual_login 接管)
|
4. 无值 → return False(交给 _wait_for_login_inputs_filled 接管)
|
||||||
|
|
||||||
不会自动 fill(如果没值就放弃,让用户自己输)。
|
不会自动 fill(如果没值就放弃,让用户自己输)。
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
page.wait_for_selector("#jc-user, #jc-pass", timeout=wait_input_sec * 1000)
|
page.wait_for_selector(
|
||||||
|
"#jc-user, #jc-pass, input[type='tel'], input[type='password']",
|
||||||
|
timeout=wait_input_sec * 1000,
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.info(
|
logger.info(
|
||||||
"platform_collector: %ds 内未出现登录 input,跳过自动登录",
|
"platform_collector: %ds 内未出现登录 input,跳过自动登录",
|
||||||
@@ -200,9 +208,23 @@ def _try_auto_sign_in(page, wait_input_sec: int = 2) -> bool:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
user_input = page.locator("#jc-user").first
|
# 多种 input selector 优先级
|
||||||
pass_input = page.locator("#jc-pass").first
|
user_input = None
|
||||||
if user_input.count() == 0 or pass_input.count() == 0:
|
for sel in ("#jc-user", "input[type='tel']", "input[autocomplete='username']"):
|
||||||
|
loc = page.locator(sel).first
|
||||||
|
if loc.count() > 0:
|
||||||
|
user_input = loc
|
||||||
|
break
|
||||||
|
if user_input is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
pass_input = None
|
||||||
|
for sel in ("#jc-pass", "input[type='password']", "input[autocomplete='current-password']"):
|
||||||
|
loc = page.locator(sel).first
|
||||||
|
if loc.count() > 0:
|
||||||
|
pass_input = loc
|
||||||
|
break
|
||||||
|
if pass_input is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
user_val = (user_input.input_value() or "").strip()
|
user_val = (user_input.input_value() or "").strip()
|
||||||
@@ -216,24 +238,42 @@ def _try_auto_sign_in(page, wait_input_sec: int = 2) -> bool:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.info(
|
# 多种按钮文本优先级:英文 Sign in > 中文登录 > submit
|
||||||
"platform_collector: 登录页已预填账号(user=%r),自动点 Sign in",
|
btn = None
|
||||||
user_val,
|
btn_text_used = ""
|
||||||
)
|
for txt in ("Sign in", "登录", "Login", "signin"):
|
||||||
btn = page.locator('button[type="submit"]:has-text("Sign in")').first
|
loc = page.locator(f"button:has-text('{txt}')").first
|
||||||
if btn.count() == 0:
|
if loc.count() > 0:
|
||||||
logger.warning("platform_collector: 未找到 Sign in 按钮")
|
btn = loc
|
||||||
|
btn_text_used = txt
|
||||||
|
break
|
||||||
|
if btn is None:
|
||||||
|
btn = page.locator("button[type='submit']").first
|
||||||
|
btn_text_used = "submit"
|
||||||
|
if btn is None or btn.count() == 0:
|
||||||
|
logger.warning("platform_collector: 未找到登录按钮")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"platform_collector: 登录页已预填账号(user=%r),自动点 %s 按钮",
|
||||||
|
user_val, btn_text_used,
|
||||||
|
)
|
||||||
btn.click()
|
btn.click()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _wait_for_login_inputs_filled(page, wait_sec: int = HUMAN_WAIT_TIMEOUT) -> bool:
|
def _wait_for_login_inputs_filled(page, wait_sec: int = HUMAN_WAIT_TIMEOUT) -> bool:
|
||||||
"""v1.1.21:等用户输入完账号密码,然后自动点 Sign in。
|
"""v1.1.21:等用户输入完账号密码,然后自动点登录按钮。
|
||||||
|
|
||||||
- 每 HUMAN_POLL_INTERVAL 秒检查 #jc-user / #jc-pass 是否有值
|
v1.1.26:按用户最新要求改回**自动点登录**行为——
|
||||||
- 两个都有值 → 自动点 Sign in → return True
|
「到了 /industries/campus/smartcampus/login 整个页面,有账号和密码可用直接点登录跳转」,
|
||||||
- 超时未填完 → return False
|
不再等用户自己点。
|
||||||
|
|
||||||
|
优先级(任一 selector 命中即视为有 input):
|
||||||
|
- user: `#jc-user` / `input[type='tel']` / `input[autocomplete='username']`
|
||||||
|
- pass: `#jc-pass` / `input[type='password']` / `input[autocomplete='current-password']`
|
||||||
|
|
||||||
|
按钮文本优先级:`Sign in` / `登录` / `Login` / `signin` / `submit`。
|
||||||
"""
|
"""
|
||||||
deadline = time.monotonic() + wait_sec
|
deadline = time.monotonic() + wait_sec
|
||||||
last_prompt_at = time.monotonic()
|
last_prompt_at = time.monotonic()
|
||||||
@@ -241,47 +281,79 @@ def _wait_for_login_inputs_filled(page, wait_sec: int = HUMAN_WAIT_TIMEOUT) -> b
|
|||||||
|
|
||||||
while time.monotonic() < deadline:
|
while time.monotonic() < deadline:
|
||||||
cur_url = page.url
|
cur_url = page.url
|
||||||
user_input = page.locator("#jc-user").first
|
|
||||||
pass_input = page.locator("#jc-pass").first
|
|
||||||
|
|
||||||
# 已不在登录页(用户可能手动点了别的)
|
# 已不在登录页(用户可能已点登录完成跳转)
|
||||||
if not _is_login_page_url_for_user(cur_url):
|
if not _is_login_page_url_for_user(cur_url):
|
||||||
logger.info(
|
logger.info(
|
||||||
"platform_collector: URL 已离开登录页(%s),停止等输入", cur_url,
|
"platform_collector: URL 已离开登录页(%s),登录完成", cur_url,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if user_input.count() > 0 and pass_input.count() > 0:
|
# 探测 input(多 selector 优先级)
|
||||||
user_val = (user_input.input_value() or "").strip()
|
user_val, pass_val = "", ""
|
||||||
pass_val = (pass_input.input_value() or "").strip()
|
user_loc, pass_loc = None, None
|
||||||
now = time.monotonic()
|
for sel in ("#jc-user", "input[type='tel']", "input[autocomplete='username']"):
|
||||||
if now - last_state_log >= HUMAN_PROMPT_INTERVAL:
|
loc = page.locator(sel).first
|
||||||
last_state_log = now
|
if loc.count() > 0:
|
||||||
|
user_loc = loc
|
||||||
|
user_val = (loc.input_value() or "").strip()
|
||||||
|
break
|
||||||
|
for sel in ("#jc-pass", "input[type='password']", "input[autocomplete='current-password']"):
|
||||||
|
loc = page.locator(sel).first
|
||||||
|
if loc.count() > 0:
|
||||||
|
pass_loc = loc
|
||||||
|
pass_val = (loc.input_value() or "").strip()
|
||||||
|
break
|
||||||
|
|
||||||
|
now = time.monotonic()
|
||||||
|
if now - last_state_log >= HUMAN_PROMPT_INTERVAL:
|
||||||
|
last_state_log = now
|
||||||
|
logger.info(
|
||||||
|
"platform_collector: 等待用户输入 user=%r pass=%r (URL=%s)",
|
||||||
|
bool(user_val), bool(pass_val), cur_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
# input 都有值 → 自动点登录按钮(v1.1.26 关键:用户最新要求自动点)
|
||||||
|
if user_val and pass_val:
|
||||||
|
btn = None
|
||||||
|
btn_text_used = ""
|
||||||
|
for txt in ("Sign in", "登录", "Login", "signin"):
|
||||||
|
loc = page.locator(f"button:has-text('{txt}')").first
|
||||||
|
if loc.count() > 0:
|
||||||
|
btn = loc
|
||||||
|
btn_text_used = txt
|
||||||
|
break
|
||||||
|
if btn is None:
|
||||||
|
btn = page.locator("button[type='submit']").first
|
||||||
|
btn_text_used = "submit"
|
||||||
|
if btn is not None and btn.count() > 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
"platform_collector: input 状态 user=%r pass=%r",
|
"platform_collector: ✅ 账号密码已填好(user=%r),自动点 %s 按钮",
|
||||||
bool(user_val), bool(pass_val),
|
user_val, btn_text_used,
|
||||||
)
|
)
|
||||||
if user_val and pass_val:
|
btn.click()
|
||||||
logger.info(
|
return True
|
||||||
"platform_collector: ✅ 用户输入完成(user=%r),自动点 Sign in",
|
logger.warning("platform_collector: input 有值但找不到登录按钮")
|
||||||
user_val,
|
|
||||||
)
|
|
||||||
btn = page.locator('button[type="submit"]:has-text("Sign in")').first
|
|
||||||
if btn.count() > 0:
|
|
||||||
btn.click()
|
|
||||||
return True
|
|
||||||
|
|
||||||
# 提醒用户
|
# 提醒用户
|
||||||
now = time.monotonic()
|
|
||||||
if now - last_prompt_at >= HUMAN_PROMPT_INTERVAL:
|
if now - last_prompt_at >= HUMAN_PROMPT_INTERVAL:
|
||||||
last_prompt_at = now
|
last_prompt_at = now
|
||||||
remaining = int(deadline - now)
|
remaining = int(deadline - now)
|
||||||
print(f"[登录] 等待用户输入账号密码... 剩余 {remaining}s")
|
if user_val and pass_val:
|
||||||
|
# 上面 click 应该已经 return,不会到这里
|
||||||
|
print(
|
||||||
|
f"[登录] ✅ 账号密码已填好(user={user_val[:3]}***),"
|
||||||
|
f"请点「登录」按钮,剩余 {remaining}s..."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"[登录] 等待用户输入账号密码... 剩余 {remaining}s"
|
||||||
|
)
|
||||||
|
|
||||||
time.sleep(HUMAN_POLL_INTERVAL)
|
time.sleep(HUMAN_POLL_INTERVAL)
|
||||||
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"platform_collector: %ds 内用户未完成输入", wait_sec,
|
"platform_collector: %ds 内用户未跳转(最后 URL=%s)", wait_sec, page.url,
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -647,22 +719,22 @@ def collect_all(
|
|||||||
else:
|
else:
|
||||||
# 2. 等 #jc-user / #jc-pass 出现(最多 2 秒)
|
# 2. 等 #jc-user / #jc-pass 出现(最多 2 秒)
|
||||||
# 若 sandbox 已预填 demo/123456 → 自动点 Sign in
|
# 若 sandbox 已预填 demo/123456 → 自动点 Sign in
|
||||||
# 若 input 为空 → 等用户输入完成后再自动点 Sign in
|
# 若 input 为空 → 等用户输入(**v1.1.24 用户自己点登录按钮**)
|
||||||
auto_clicked = _try_auto_sign_in(page, wait_input_sec=2)
|
auto_clicked = _try_auto_sign_in(page, wait_input_sec=2)
|
||||||
if auto_clicked:
|
if auto_clicked:
|
||||||
logger.info(
|
logger.info(
|
||||||
"platform_collector: ✅ 自动登录成功(预填 demo),等 URL 跳到 /app/"
|
"platform_collector: ✅ 自动登录成功(预填 demo),等 URL 跳到 /app/"
|
||||||
)
|
)
|
||||||
elif not headless:
|
elif not headless:
|
||||||
# 3. input 为空:等用户输入 → 自动点 Sign in
|
# 3. input 为空:等用户输入 → **用户自己点 Sign in**(脚本不抢按钮)
|
||||||
if _wait_for_login_inputs_filled(page, wait_sec=human_wait_timeout):
|
if _wait_for_login_inputs_filled(page, wait_sec=human_wait_timeout):
|
||||||
logger.info(
|
logger.info(
|
||||||
"platform_collector: ✅ 用户输入完成并点击,等 URL 跳到 /app/"
|
"platform_collector: ✅ 用户完成输入并跳转,等 URL 跳到 /app/"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# 超时未输入 → fallback 到原来的多信号等待
|
# 超时未跳转 → fallback 到原来的多信号等待
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"platform_collector: 用户未输入完成,fallback 到 _wait_for_manual_login"
|
"platform_collector: 用户未跳转,fallback 到 _wait_for_manual_login"
|
||||||
)
|
)
|
||||||
_wait_for_manual_login(page, wait_sec=human_wait_timeout)
|
_wait_for_manual_login(page, wait_sec=human_wait_timeout)
|
||||||
else:
|
else:
|
||||||
@@ -681,6 +753,35 @@ def collect_all(
|
|||||||
)
|
)
|
||||||
# 不强行 reload —— 让用户决定是否手工刷新
|
# 不强行 reload —— 让用户决定是否手工刷新
|
||||||
|
|
||||||
|
# 4.5. v1.1.24:sandbox 可能登录后把人踢回 SPA 二级登录页
|
||||||
|
# (/industries/campus/smartcampus/login)。如果 URL 落在
|
||||||
|
# 这个二级登录页,再走一次 _try_auto_sign_in(已经扩展支持
|
||||||
|
# 中文「登录」按钮);若 SPA 登录页 input 有预填账号 → 自动点;
|
||||||
|
# 若 input 空 → 等用户输入并**自己点登录**(脚本不抢按钮)。
|
||||||
|
cur_url_after_stable = page.url.lower()
|
||||||
|
if "/login" in cur_url_after_stable or "/signin" in cur_url_after_stable:
|
||||||
|
logger.warning(
|
||||||
|
"platform_collector: 登录后仍落在登录页(%s),"
|
||||||
|
"v1.1.24 触发 SPA 二级登录兜底",
|
||||||
|
page.url,
|
||||||
|
)
|
||||||
|
spa_auto = _try_auto_sign_in(page, wait_input_sec=2)
|
||||||
|
if spa_auto:
|
||||||
|
logger.info(
|
||||||
|
"platform_collector: ✅ SPA 二级登录页已自动登录,"
|
||||||
|
"等 URL 跳到 /app/ 或 /select"
|
||||||
|
)
|
||||||
|
_wait_for_url_stable(page, ("/app/", "/select"), max_wait_sec=30)
|
||||||
|
elif not headless:
|
||||||
|
if _wait_for_login_inputs_filled(page, wait_sec=human_wait_timeout):
|
||||||
|
_wait_for_url_stable(page, ("/app/", "/select"), max_wait_sec=30)
|
||||||
|
else:
|
||||||
|
_wait_for_manual_login(page, wait_sec=human_wait_timeout)
|
||||||
|
else:
|
||||||
|
raise LoginTimeoutError(
|
||||||
|
f"SPA 二级登录页 input 空且 headless 无法手工登录(URL={page.url})"
|
||||||
|
)
|
||||||
|
|
||||||
# 5. v1.1.22:显式跳到 SPA_HOME_URL(/app/home),等侧边栏 link 出现
|
# 5. v1.1.22:显式跳到 SPA_HOME_URL(/app/home),等侧边栏 link 出现
|
||||||
# 避免 sandbox 在 /select 中间页时直接找 sidebar link 找不到
|
# 避免 sandbox 在 /select 中间页时直接找 sidebar link 找不到
|
||||||
if "/app/home" not in page.url.lower():
|
if "/app/home" not in page.url.lower():
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
SKILL_SLUG = "alert-contract-expiring-hr"
|
SKILL_SLUG = "alert-contract-expiring-hr"
|
||||||
SKILL_VERSION = "1.1.23"
|
SKILL_VERSION = "1.1.26"
|
||||||
LOG_LOGGER_NAME = "openclaw.skill.alert_contract_expiring_hr"
|
LOG_LOGGER_NAME = "openclaw.skill.alert_contract_expiring_hr"
|
||||||
PLATFORM_KIT_MIN_VERSION = "1.2.11"
|
PLATFORM_KIT_MIN_VERSION = "1.2.11"
|
||||||
|
|
||||||
|
|||||||
@@ -1279,6 +1279,8 @@ class _FakePage:
|
|||||||
|
|
||||||
- .url: 字符串
|
- .url: 字符串
|
||||||
- 支持外部修改 .url 模拟用户登录跳转
|
- 支持外部修改 .url 模拟用户登录跳转
|
||||||
|
- v1.1.24:新增 .locator() 返回 _FakeLocatorNoOp,让
|
||||||
|
_wait_for_login_inputs_filled 的 selector 探测不抛 AttributeError
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, initial_url: str = "about:blank") -> None:
|
def __init__(self, initial_url: str = "about:blank") -> None:
|
||||||
@@ -1287,6 +1289,10 @@ class _FakePage:
|
|||||||
self.reload_calls: int = 0
|
self.reload_calls: int = 0
|
||||||
self.click_calls: int = 0
|
self.click_calls: int = 0
|
||||||
|
|
||||||
|
def locator(self, selector: str): # noqa: ARG002
|
||||||
|
"""v1.1.24 扩展:测试 _wait_for_login_inputs_filled 用,返回空 locator。"""
|
||||||
|
return _FakeLocator(count=0)
|
||||||
|
|
||||||
|
|
||||||
def test_wait_for_url_stable_immediate_match() -> tuple[bool, str]:
|
def test_wait_for_url_stable_immediate_match() -> tuple[bool, str]:
|
||||||
"""_wait_for_url_stable: URL 已含目标 + 稳定 → 立即返回 True。"""
|
"""_wait_for_url_stable: URL 已含目标 + 稳定 → 立即返回 True。"""
|
||||||
@@ -1366,6 +1372,222 @@ def test_wait_for_manual_login_no_goto() -> tuple[bool, str]:
|
|||||||
pc.URL_STABLE_REQUIRED_S = orig_stable
|
pc.URL_STABLE_REQUIRED_S = orig_stable
|
||||||
|
|
||||||
|
|
||||||
|
# ---------- v1.1.24: _try_auto_sign_in SPA 二级登录页(中文「登录」按钮)----------
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeLocator:
|
||||||
|
"""v1.1.24 _try_auto_sign_in 测试用的简易 Playwright Locator mock。
|
||||||
|
|
||||||
|
支持的 API:
|
||||||
|
- .count() -> int
|
||||||
|
- .input_value() -> str
|
||||||
|
- .click() -> None
|
||||||
|
- .first -> 自身
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
count: int = 0,
|
||||||
|
value: str = "",
|
||||||
|
click_log: list | None = None,
|
||||||
|
) -> None:
|
||||||
|
self._count = count
|
||||||
|
self._value = value
|
||||||
|
self._click_log = click_log if click_log is not None else []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first(self) -> "_FakeLocator":
|
||||||
|
return self
|
||||||
|
|
||||||
|
def count(self) -> int:
|
||||||
|
return self._count
|
||||||
|
|
||||||
|
def input_value(self) -> str:
|
||||||
|
return self._value
|
||||||
|
|
||||||
|
def click(self) -> None:
|
||||||
|
self._click_log.append(self._value or "clicked")
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeLocatorRouter:
|
||||||
|
"""根据 selector 返回对应 _FakeLocator 的路由器。
|
||||||
|
|
||||||
|
selectors: dict[selector_str, _FakeLocator]
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, selectors: dict[str, _FakeLocator], page) -> None:
|
||||||
|
self._selectors = selectors
|
||||||
|
self._page = page
|
||||||
|
|
||||||
|
def __call__(self, sel: str):
|
||||||
|
"""page.locator(sel) 形式调用。"""
|
||||||
|
if sel in self._selectors:
|
||||||
|
return self._selectors[sel]
|
||||||
|
return _FakeLocator(count=0)
|
||||||
|
|
||||||
|
def __getattr__(self, sel: str):
|
||||||
|
# loc.page 已存在则按 selector 路由
|
||||||
|
if sel in self._selectors:
|
||||||
|
return self._selectors[sel]
|
||||||
|
# fallback:未注册的 selector 都返回空 locator
|
||||||
|
return _FakeLocator(count=0)
|
||||||
|
|
||||||
|
|
||||||
|
class _FakePlaywrightPage:
|
||||||
|
"""v1.1.24 _try_auto_sign_in 测试用的 page mock。
|
||||||
|
|
||||||
|
usage:
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/industries/campus/smartcampus/login",
|
||||||
|
selectors={
|
||||||
|
"input[type='tel']": _FakeLocator(count=1, value="18677308191"),
|
||||||
|
"input[type='password']": _FakeLocator(count=1, value="***"),
|
||||||
|
"button:has-text('登录')": _FakeLocator(count=1, click_log=click_log),
|
||||||
|
},
|
||||||
|
wait_for_selector_log=wait_log,
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
url: str = "about:blank",
|
||||||
|
selectors: dict[str, _FakeLocator] | None = None,
|
||||||
|
wait_for_selector_log: list | None = None,
|
||||||
|
wait_selector_should_raise: bool = False,
|
||||||
|
) -> None:
|
||||||
|
self.url = url
|
||||||
|
self._selectors = selectors or {}
|
||||||
|
self._wait_log = wait_for_selector_log if wait_for_selector_log is not None else []
|
||||||
|
self._wait_should_raise = wait_selector_should_raise
|
||||||
|
|
||||||
|
def wait_for_selector(self, selector: str, timeout: int = 0) -> None:
|
||||||
|
self._wait_log.append(selector)
|
||||||
|
if self._wait_should_raise:
|
||||||
|
raise Exception("fake: timeout")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def locator(self):
|
||||||
|
return _FakeLocatorRouter(self._selectors, self)
|
||||||
|
|
||||||
|
|
||||||
|
def test_try_auto_sign_in_spa_login_chinese_button() -> tuple[bool, str]:
|
||||||
|
"""v1.1.24:SPA 二级登录页(/industries/campus/smartcampus/login),
|
||||||
|
input 用 `input[type='tel']` / `input[type='password']`,
|
||||||
|
按钮中文「登录」。预填有值 → 自动点登录。
|
||||||
|
"""
|
||||||
|
from service.platform_collector import _try_auto_sign_in
|
||||||
|
|
||||||
|
click_log: list[str] = []
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/industries/campus/smartcampus/login",
|
||||||
|
selectors={
|
||||||
|
"input[type='tel']": _FakeLocator(count=1, value="18677308191"),
|
||||||
|
"input[type='password']": _FakeLocator(count=1, value="dummy"),
|
||||||
|
"button:has-text('登录')": _FakeLocator(count=1, click_log=click_log),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if not _try_auto_sign_in(page, wait_input_sec=2):
|
||||||
|
return False, "SPA 二级登录页预填应自动点 登录"
|
||||||
|
if not click_log:
|
||||||
|
return False, f"未触发点击: {click_log}"
|
||||||
|
return True, f"SPA 二级登录页中文按钮自动点 OK(click_log={click_log})"
|
||||||
|
|
||||||
|
|
||||||
|
def test_try_auto_sign_in_root_sign_in_english_button() -> tuple[bool, str]:
|
||||||
|
"""v1.1.24(向后兼容):根域登录页(https://sandbox.jc2009.com/),
|
||||||
|
input 用 `#jc-user` / `#jc-pass`,按钮英文「Sign in」。预填有值 → 自动点。
|
||||||
|
"""
|
||||||
|
from service.platform_collector import _try_auto_sign_in
|
||||||
|
|
||||||
|
click_log: list[str] = []
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/",
|
||||||
|
selectors={
|
||||||
|
"#jc-user": _FakeLocator(count=1, value="demo"),
|
||||||
|
"#jc-pass": _FakeLocator(count=1, value="123456"),
|
||||||
|
"button:has-text('Sign in')": _FakeLocator(count=1, click_log=click_log),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if not _try_auto_sign_in(page, wait_input_sec=2):
|
||||||
|
return False, "根域登录页预填应自动点 Sign in"
|
||||||
|
if not click_log:
|
||||||
|
return False, f"未触发点击: {click_log}"
|
||||||
|
return True, f"根域登录页 Sign in 自动点 OK(click_log={click_log})"
|
||||||
|
|
||||||
|
|
||||||
|
def test_try_auto_sign_in_no_input_returns_false() -> tuple[bool, str]:
|
||||||
|
"""v1.1.24:input 为空(用户还没输入)→ 返回 False,不点按钮。"""
|
||||||
|
from service.platform_collector import _try_auto_sign_in
|
||||||
|
|
||||||
|
click_log: list[str] = []
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/industries/campus/smartcampus/login",
|
||||||
|
selectors={
|
||||||
|
"input[type='tel']": _FakeLocator(count=1, value=""), # 空
|
||||||
|
"input[type='password']": _FakeLocator(count=1, value="123"),
|
||||||
|
"button:has-text('登录')": _FakeLocator(count=1, click_log=click_log),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if _try_auto_sign_in(page, wait_input_sec=2):
|
||||||
|
return False, "user 空时不应自动点"
|
||||||
|
if click_log:
|
||||||
|
return False, f"未填完不应点击: {click_log}"
|
||||||
|
return True, "input 空返回 False 不点 OK"
|
||||||
|
|
||||||
|
|
||||||
|
def test_try_auto_sign_in_selector_timeout_returns_false() -> tuple[bool, str]:
|
||||||
|
"""v1.1.24:等 input 超时(如 URL 已是 SPA home,无登录 input)→ 返回 False。"""
|
||||||
|
from service.platform_collector import _try_auto_sign_in
|
||||||
|
|
||||||
|
click_log: list[str] = []
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/industries/campus/smartcampus/app/home",
|
||||||
|
selectors={}, # 没有任何 input
|
||||||
|
wait_selector_should_raise=True,
|
||||||
|
)
|
||||||
|
if _try_auto_sign_in(page, wait_input_sec=1):
|
||||||
|
return False, "无登录 input 应返回 False"
|
||||||
|
if click_log:
|
||||||
|
return False, f"无 input 不应点击: {click_log}"
|
||||||
|
return True, "无登录 input 超时返回 False OK"
|
||||||
|
|
||||||
|
|
||||||
|
def test_wait_for_login_inputs_filled_auto_click_v1_26() -> tuple[bool, str]:
|
||||||
|
"""v1.1.26:`_wait_for_login_inputs_filled` **自动点登录按钮**——
|
||||||
|
按用户最新要求:「到了 /industries/campus/smartcampus/login 整个页面,
|
||||||
|
有账号和密码可用直接点登录跳转」。
|
||||||
|
|
||||||
|
input 有值时点击 `button:has-text('登录')` 或 `Sign in`(多按钮文本优先级)。
|
||||||
|
"""
|
||||||
|
from service import platform_collector as pc
|
||||||
|
|
||||||
|
orig_poll = pc.HUMAN_POLL_INTERVAL
|
||||||
|
orig_prompt = pc.HUMAN_PROMPT_INTERVAL
|
||||||
|
pc.HUMAN_POLL_INTERVAL = 0.2
|
||||||
|
pc.HUMAN_PROMPT_INTERVAL = 0.2
|
||||||
|
try:
|
||||||
|
click_log: list[str] = []
|
||||||
|
page = _FakePlaywrightPage(
|
||||||
|
url="https://sandbox.jc2009.com/industries/campus/smartcampus/login",
|
||||||
|
selectors={
|
||||||
|
"input[type='tel']": _FakeLocator(count=1, value="18677308191"),
|
||||||
|
"input[type='password']": _FakeLocator(count=1, value="dummy"),
|
||||||
|
"button:has-text('登录')": _FakeLocator(count=1, click_log=click_log),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
result = pc._wait_for_login_inputs_filled(page, wait_sec=5)
|
||||||
|
if not result:
|
||||||
|
return False, "input 有值应自动点登录 → return True"
|
||||||
|
|
||||||
|
if not click_log:
|
||||||
|
return False, f"v1.1.26 应自动点登录按钮,但 click_log={click_log}"
|
||||||
|
return True, f"v1.1.26 自动点登录按钮 OK(click_log={click_log})"
|
||||||
|
finally:
|
||||||
|
pc.HUMAN_POLL_INTERVAL = orig_poll
|
||||||
|
pc.HUMAN_PROMPT_INTERVAL = orig_prompt
|
||||||
|
|
||||||
|
|
||||||
# ---------- v1.1.18: show-config / logs-list ----------
|
# ---------- v1.1.18: show-config / logs-list ----------
|
||||||
|
|
||||||
|
|
||||||
@@ -1639,6 +1861,11 @@ def main() -> int:
|
|||||||
_run("login_flow/wait_url_stable_transition", test_wait_for_url_stable_transition)
|
_run("login_flow/wait_url_stable_transition", test_wait_for_url_stable_transition)
|
||||||
_run("login_flow/wait_url_stable_timeout", test_wait_for_url_stable_timeout)
|
_run("login_flow/wait_url_stable_timeout", test_wait_for_url_stable_timeout)
|
||||||
_run("login_flow/wait_manual_login_no_goto", test_wait_for_manual_login_no_goto)
|
_run("login_flow/wait_manual_login_no_goto", test_wait_for_manual_login_no_goto)
|
||||||
|
_run("login_flow/auto_sign_in_spa_chinese_button", test_try_auto_sign_in_spa_login_chinese_button)
|
||||||
|
_run("login_flow/auto_sign_in_root_english_button", test_try_auto_sign_in_root_sign_in_english_button)
|
||||||
|
_run("login_flow/auto_sign_in_no_input_returns_false", test_try_auto_sign_in_no_input_returns_false)
|
||||||
|
_run("login_flow/auto_sign_in_selector_timeout_returns_false", test_try_auto_sign_in_selector_timeout_returns_false)
|
||||||
|
_run("login_flow/wait_login_inputs_filled_auto_click_v1_26", test_wait_for_login_inputs_filled_auto_click_v1_26)
|
||||||
_run("show_config/masks_tokens", test_show_config_masks_tokens)
|
_run("show_config/masks_tokens", test_show_config_masks_tokens)
|
||||||
_run("show_config/skips_empty", test_show_config_skips_empty)
|
_run("show_config/skips_empty", test_show_config_skips_empty)
|
||||||
_run("show_config/skips_comments", test_show_config_skips_comments)
|
_run("show_config/skips_comments", test_show_config_skips_comments)
|
||||||
|
|||||||
Reference in New Issue
Block a user