2026-03-10 22:31:30 +08:00
|
|
|
|
"""
|
|
|
|
|
|
Mumu模拟器测试
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
2026-03-12 20:13:24 +08:00
|
|
|
|
import pyautogui
|
|
|
|
|
|
import os
|
|
|
|
|
|
import time
|
2026-03-10 22:31:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_start_emulator_sequence(emulator):
|
|
|
|
|
|
"""测试模拟器启动和操作序列"""
|
2026-03-12 20:13:24 +08:00
|
|
|
|
time.sleep(3)
|
2026-03-10 22:31:30 +08:00
|
|
|
|
emulator.start()
|
2026-03-12 20:13:24 +08:00
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(__file__)
|
|
|
|
|
|
start_image_path = os.path.join(script_dir, "start.png")
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(start_image_path):
|
|
|
|
|
|
pytest.fail(f"start.png 图片文件不存在: {start_image_path}")
|
|
|
|
|
|
|
|
|
|
|
|
print("正在查找 start.png 图片...")
|
|
|
|
|
|
location = None
|
|
|
|
|
|
for _ in range(10):
|
|
|
|
|
|
try:
|
|
|
|
|
|
location = pyautogui.locateOnScreen(start_image_path, confidence=0.8)
|
|
|
|
|
|
if location:
|
|
|
|
|
|
break
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
pass
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
if not location:
|
|
|
|
|
|
print("未找到 start.png,退出 pytest")
|
|
|
|
|
|
pytest.exit("未在屏幕上找到 start.png 图片,测试终止")
|
|
|
|
|
|
|
|
|
|
|
|
center = pyautogui.center(location)
|
|
|
|
|
|
pyautogui.click(center)
|
|
|
|
|
|
print(f"已点击 start.png,位置: {center}")
|
|
|
|
|
|
|
2026-03-10 22:31:30 +08:00
|
|
|
|
assert emulator.is_running(), "模拟器启动失败"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_sequence(emulator):
|
|
|
|
|
|
"""测试按顺序执行任务"""
|
2026-03-12 20:13:24 +08:00
|
|
|
|
time.sleep(3)
|
2026-03-10 22:31:30 +08:00
|
|
|
|
if not emulator.is_running():
|
|
|
|
|
|
pytest.skip("模拟器未运行")
|
|
|
|
|
|
|
|
|
|
|
|
emulator.run_sequence()
|