Add pytest test case for flomo-ai config and start page verification

This commit is contained in:
2026-03-15 23:26:31 +08:00
parent c6ae059e65
commit 893b5356a9
4 changed files with 117 additions and 0 deletions

BIN
mumu-pytest/config.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

BIN
mumu-pytest/start_page.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

View File

@@ -0,0 +1,117 @@
"""
Flomo-ai 应用配置和启动页面测试
"""
import pytest
import pyautogui
import os
import time
def test_flomo_ai_config_and_start(emulator):
"""
测试 flomo-ai 应用的配置和启动页面
1. 检查是否有 config.png有就通过没有测试失败
2. 点击 config.png
3. 检查界面是否有 start_page.png有就通过没有测试失败
4. 点击 start_page.png
"""
# 确保模拟器正在运行,如果未运行则启动
if not emulator.is_running():
print("模拟器未运行,正在启动...")
emulator.start()
time.sleep(10) # 等待模拟器启动完成
# 将模拟器窗口置顶
emulator.bring_to_front()
time.sleep(5) # 增加等待时间,确保应用完全加载
# 将模拟器窗口置顶
emulator.bring_to_front()
time.sleep(3)
script_dir = os.path.dirname(__file__)
# 1. 检查是否有 config.png
config_image_path = os.path.join(script_dir, "config.png")
if not os.path.exists(config_image_path):
pytest.fail(f"config.png 图片文件不存在: {config_image_path}")
print("正在查找 config.png 图片...")
print(f"图片路径: {config_image_path}")
print(f"图片存在: {os.path.exists(config_image_path)}")
config_location = None
for i in range(15):
try:
# 尝试不同的 confidence 值
for confidence in [0.9, 0.8, 0.7, 0.6]:
config_location = pyautogui.locateOnScreen(config_image_path, confidence=confidence)
if config_location:
print(f"{i+1} 次尝试在 confidence={confidence} 时找到 config.png")
break
if config_location:
break
else:
print(f"{i+1} 次尝试未找到 config.png")
except Exception as e:
print(f"{i+1} 次尝试出现异常: {e}")
time.sleep(1)
if not config_location:
# 截图保存当前屏幕状态用于调试
screenshot_path = os.path.join(script_dir, "debug_config_not_found.png")
pyautogui.screenshot(screenshot_path)
print(f"未找到 config.png已保存调试截图: {screenshot_path}")
pytest.fail("未找到 config.png 图片")
print(f"找到 config.png位置: {config_location}")
# 2. 点击 config.png
center = pyautogui.center(config_location)
pyautogui.click(center)
print(f"已点击 config.png位置: {center}")
time.sleep(3) # 等待配置页面加载
# 3. 检查界面是否有 start_page.png
start_page_image_path = os.path.join(script_dir, "start_page.png")
if not os.path.exists(start_page_image_path):
pytest.fail(f"start_page.png 图片文件不存在: {start_page_image_path}")
print("正在查找 start_page.png 图片...")
print(f"图片路径: {start_page_image_path}")
start_page_location = None
for i in range(15):
try:
start_page_location = pyautogui.locateOnScreen(start_page_image_path, confidence=0.7)
if start_page_location:
print(f"{i+1} 次尝试找到 start_page.png")
break
else:
print(f"{i+1} 次尝试未找到 start_page.png")
except Exception as e:
print(f"{i+1} 次尝试出现异常: {e}")
time.sleep(1)
if not start_page_location:
# 截图保存当前屏幕状态用于调试
screenshot_path = os.path.join(script_dir, "debug_start_page_not_found.png")
pyautogui.screenshot(screenshot_path)
print(f"未找到 start_page.png已保存调试截图: {screenshot_path}")
pytest.fail("未找到 start_page.png 图片")
print(f"找到 start_page.png位置: {start_page_location}")
# 4. 点击 start_page.png
center = pyautogui.center(start_page_location)
pyautogui.click(center)
print(f"已点击 start_page.png位置: {center}")
time.sleep(3) # 等待页面响应
# 验证测试成功
assert config_location is not None, "config.png 未找到,测试失败"
assert start_page_location is not None, "start_page.png 未找到,测试失败"
print("Flomo-ai 配置和启动页面测试通过!")