更新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

@@ -4,6 +4,7 @@ Mumu模拟器 pytest 测试框架
import pytest
import pyautogui
import pygetwindow as gw
import time
import os
import subprocess
@@ -48,6 +49,24 @@ class MumuEmulator:
if not self.is_running():
subprocess.Popen(MUMU_EXE_PATH)
time.sleep(5)
self.bring_to_front()
def bring_to_front(self):
"""将模拟器窗口置顶"""
try:
windows = gw.getWindowsWithTitle("MuMu")
for window in windows:
if window.title:
window.activate()
window.restore()
time.sleep(0.5)
print(f"已将窗口置顶: {window.title}")
return True
print("未找到MuMu模拟器窗口")
return False
except Exception as e:
print(f"置顶窗口失败: {e}")
return False
def find_and_click(self, image_name, confidence=0.8, timeout=30):
"""查找图片并点击"""
@@ -106,11 +125,11 @@ class MumuEmulator:
def run_sequence(self):
"""按顺序执行任务"""
self.bring_to_front()
time.sleep(30)
sequence = [
"start",
"running",
"web",
"web.address",
"web_address",
"web_goon",
"web_debug",
"web_debug_apk",
@@ -121,16 +140,19 @@ class MumuEmulator:
]
for image_name in sequence:
if image_name == "web.address":
if self.check_image_exists("web.address"):
if image_name == "web_address":
for _ in range(60):
if self.check_image_exists("web_address"):
time.sleep(1)
self.type_text(WEB_URL)
time.sleep(0.5)
self.press_enter()
break
time.sleep(1)
self.type_text(WEB_URL)
time.sleep(0.5)
self.press_enter()
else:
print("web.address 图片不存在跳过输入URL")
print("web_address 图片不存在跳过输入URL")
else:
self.find_and_click(image_name, timeout=10)
self.find_and_click(image_name, timeout=60)
time.sleep(2)
def close(self):