更新mumu-pytest测试框架,修复build.gradle.kts依赖问题

This commit is contained in:
2026-03-12 20:13:24 +08:00
parent 9b3c878159
commit cb5c3c7dc9
7 changed files with 168 additions and 64 deletions

View File

@@ -3,17 +3,48 @@ Mumu模拟器测试
"""
import pytest
import pyautogui
import os
import time
def test_start_emulator_sequence(emulator):
"""测试模拟器启动和操作序列"""
assert not emulator.is_running(), "模拟器已启动"
time.sleep(3)
emulator.start()
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}")
assert emulator.is_running(), "模拟器启动失败"
def test_run_sequence(emulator):
"""测试按顺序执行任务"""
time.sleep(3)
if not emulator.is_running():
pytest.skip("模拟器未运行")
@@ -22,6 +53,7 @@ def test_run_sequence(emulator):
def test_close_emulator(emulator):
"""测试关闭模拟器"""
time.sleep(3)
if emulator.is_running():
emulator.close()
assert not emulator.is_running(), "模拟器关闭失败"