Files
file-templates/wxwork.robot
2025-05-08 13:17:02 +00:00

81 lines
3.3 KiB
Plaintext

*** Settings ***
Library FlaUILibrary
Library OperatingSystem
Library Collections
Library json
*** Variables ***
${RESULTS_DIR} ${CURDIR}\\results
${AVATARS_DIR} ${RESULTS_DIR}\\avatars
*** Test Cases ***
Check If WXWork Is Running
${wxwork_running}= Is WXWork Running
Log WXWork is running: ${wxwork_running}
Click Calculator Button
# 等待计算器窗口出现
Wait Until Element Exist //Window[@Name="计算器" or @Name="Calculator"]
# 点击数字按钮
Click //Button[@Name="5" or @AutomationId="num5Button"]
Click //Button[@Name="+" or @AutomationId="plusButton"]
Click //Button[@Name="3" or @AutomationId="num3Button"]
Click //Button[@Name="=" or @AutomationId="equalButton"]
Get WeChat Work Conversation List
# 检查企业微信是否运行
${wxwork_running}= Is WXWork Running
Log WXWork is running: ${wxwork_running}
Run Keyword If not ${wxwork_running} Fail 企业微信(WXWork.exe)未运行,请先启动企业微信
# 创建结果目录
Create Directory ${RESULTS_DIR}
Create Directory ${AVATARS_DIR}
# 等待企业微信窗口出现
Wait Until Element Exist //Window[contains(@Name, "企业微信")]
Wait Until Element Exist //Pane[@Name="TitleBarWindow"]
# Wait Until Element Exist //Tree[@Name="clientbg"]
# 等待对话列表加载
Wait Until Element Exist //Tree[@Name="GeneralConversationItemView"]
# 创建一个空列表用于存储对话数据
@{conversations}= Create List
# 查找所有对话项
${conversation_items}= Find All Elements //Tree[@Name="GeneralConversationItemView"]
# 遍历每个对话项
FOR ${item} IN @{conversation_items}
# 获取当前对话项的XPath
${item_xpath}= Set Variable ${item.Xpath}
# 获取头像元素
${avatar_elements}= Find All Elements ${item_xpath}//TreeItem[@Name="avataricon"]
${avatar_element}= Set Variable ${avatar_elements}[0]
# 截取头像图片
${timestamp}= Evaluate int(round(time.time() * 1000)) time
${avatar_path}= Set Variable ${AVATARS_DIR}\\avatar_${timestamp}.png
${screenshot}= Take Screenshot ${avatar_element}
Copy File ${screenshot} ${avatar_path}
# 获取用户名元素
${username_elements}= Find All Elements ${item_xpath}//TreeItem[@Name="groupbuddyname"]
${username}= Get Name From Element ${username_elements}[0]
# 创建对话数据并添加到列表
${conversation}= Create Dictionary name=${username} avatar=file://${avatar_path}
Append To List ${conversations} ${conversation}
END
# 将对话列表保存为JSON文件
${json_string}= Evaluate json.dumps($conversations, ensure_ascii=False, indent=2) json
Create File ${RESULTS_DIR}\\conversations.json ${json_string}
*** Keywords ***
Is WXWork Running
${process_output}= Run tasklist /FI "IMAGENAME eq WXWork.exe" /FO CSV /NH
${is_running}= Run Keyword And Return Status Should Contain ${process_output} WXWork.exe
RETURN ${is_running}