diff --git a/WeiXin/T1_OpenChat_ActionTest.py b/WeiXin/T1_OpenChat_ActionTest.py index eed01c6..db7c258 100644 --- a/WeiXin/T1_OpenChat_ActionTest.py +++ b/WeiXin/T1_OpenChat_ActionTest.py @@ -1,4 +1,17 @@ # coding=utf-8 +""" +T1_OpenChat_ActionTest.py - 微信对话框打开测试 (UI Navigation Test) + +【核心功能】 +- 自动化导航:模拟点击搜索、输入好友名称、进入聊天窗口的完整 UI 流程。 +- 环境初始化:执行测试前清理旧的日志和输出文件。 +- 容错处理:支持通过 UI 树定位或坐标点击两种方式查找搜索结果。 + +【使用场景】 +- 验证 UIAutomator2 是否能正常驱动微信。 +- 当搜索好友功能失效或微信 UI 改版时进行调试。 +- 作为自动化巡课流程的第一步(确保机器人处于正确的聊天界面)。 +""" import uiautomator2 as u2 import time import logging diff --git a/WeiXin/T4_Text_StaticTest.py b/WeiXin/T4_Text_StaticTest.py index 52ea93f..2bb1404 100644 --- a/WeiXin/T4_Text_StaticTest.py +++ b/WeiXin/T4_Text_StaticTest.py @@ -1,4 +1,17 @@ # coding=utf-8 +""" +T4_Text_StaticTest.py - 纯文本消息识别与合并测试 (Text Message Static Test) + +【核心功能】 +- 静态文本分析:专门针对文字消息进行 OCR 识别。 +- 消息合并逻辑:模拟机器人将同一发送者、在短时间内发送的多行文字合并为一条消息的逻辑。 +- 视觉验证:生成标记了识别结果的调试图片 (T4_Debug.jpg)。 + +【使用场景】 +- 验证多行长文字消息是否能被正确合并。 +- 调试文字消息的发送者判定(特别是长文本换行后的判定)。 +- 在不干扰手机交互的情况下,快速验证文本 OCR 的准确性。 +""" import os import sys import logging diff --git a/WeiXin/T5_SendText.py b/WeiXin/T5_SendText_ActionTest.py similarity index 78% rename from WeiXin/T5_SendText.py rename to WeiXin/T5_SendText_ActionTest.py index 73b790b..2ccba7d 100644 --- a/WeiXin/T5_SendText.py +++ b/WeiXin/T5_SendText_ActionTest.py @@ -1,4 +1,17 @@ # coding=utf-8 +""" +T5_SendText_ActionTest.py - 文本输入与发送功能测试 (Input & Send Action Test) + +【核心功能】 +- 输入法切换:测试自动切换到微信输入模式逻辑。 +- 鲁棒输入:验证通过 UI 元素(EditText)或坐标点进行文字填充。 +- 发送动作:模拟点击“发送”按钮并验证发送是否成功。 + +【使用场景】 +- 调试机器人“会写不会发”的问题。 +- 验证在不同输入法环境下(如搜狗、系统默认)的输入兼容性。 +- 测试输入框定位算法是否能避开键盘遮挡。 +""" import os import sys import logging diff --git a/WeiXin/WxUtil.py b/WeiXin/WxUtil.py index ce56993..8554c07 100644 --- a/WeiXin/WxUtil.py +++ b/WeiXin/WxUtil.py @@ -67,26 +67,41 @@ def parse_wechat_time(time_str): dt = datetime.combine(yesterday, datetime.min.time().replace(hour=h, minute=m)) return dt.strftime("%Y-%m-%d %H:%M") - # 3. 星期X HH:mm - weekdays = {"星期一": 0, "星期二": 1, "星期三": 2, "星期四": 3, "星期五": 4, "星期六": 5, "星期日": 6} - for w_str, w_idx in weekdays.items(): + # 3. 星期X / 周X HH:mm + weekdays_map = { + "星期一": 0, "星期二": 1, "星期三": 2, "星期四": 3, "星期五": 4, "星期六": 5, "星期日": 6, + "周一": 0, "周二": 1, "周三": 2, "周四": 3, "周五": 4, "周六": 5, "周日": 6 + } + for w_str, w_idx in weekdays_map.items(): if w_str in clean_str: + # 提取时间部分 (支持 "周三 10:03" 或 "周三10:03") t_part = clean_str.replace(w_str, "").strip() - if re.match(r'^\d{1,2}:\d{2}$', t_part): - h, m = map(int, t_part.split(':')) - current_weekday = now.weekday() - # 计算日期回退天数 (mod 7 确保是过去的一周内) - delta_days = (current_weekday - w_idx) % 7 - # 如果 delta_days 是 0 且当前时间比消息时间早 (不可能发生,除非穿越),说明是今天 - # 但通常"星期X"不显示今天,今天显示 HH:mm - # 如果 delta_days == 0,可能是上周的今天?微信通常显示 "上周X"? - # 简单起见,认为是今天或过去7天内的那天 - if delta_days == 0 and datetime.now().time() < datetime.min.time().replace(hour=h, minute=m): - delta_days = 7 # 上周 - - target_date = today - timedelta(days=delta_days) + time_match = re.search(r'(\d{1,2}):(\d{2})', t_part) + + h, m = 0, 0 + if time_match: + h, m = map(int, time_match.groups()) + + current_weekday = now.weekday() + # 计算日期回退天数 (mod 7 确保是过去的一周内) + delta_days = (current_weekday - w_idx) % 7 + + # 如果 delta_days 是 0,且当前时间比解析出的时间早,说明是上周的今天 + # 微信通常只有在真的“过去”才会显示星期几 + if delta_days == 0 and time_match: + if now.hour < h or (now.hour == h and now.minute < m): + delta_days = 7 + elif delta_days == 0 and not time_match: + # 只有“周三”没有时间,通常指最近的一个周三(如果今天是周三,可能指上周三) + # 但为了简单,如果今天是周三且没时间,我们暂定为今天 + pass + + target_date = today - timedelta(days=delta_days) + if time_match: dt = datetime.combine(target_date, datetime.min.time().replace(hour=h, minute=m)) return dt.strftime("%Y-%m-%d %H:%M") + else: + return target_date.strftime("%Y-%m-%d 00:00") # 4. YYYY年MM月DD日 HH:mm # 简单匹配年月日 diff --git a/WeiXin/__pycache__/WxUtil.cpython-310.pyc b/WeiXin/__pycache__/WxUtil.cpython-310.pyc index 4c5d739..c71beb8 100644 Binary files a/WeiXin/__pycache__/WxUtil.cpython-310.pyc and b/WeiXin/__pycache__/WxUtil.cpython-310.pyc differ