feat: 添加模拟器卸载应用测试功能并优化构建配置
- 新增模拟器卸载应用UI测试功能及相关测试图片 - 添加本地Gradle初始化脚本和构建脚本 - 更新Gradle版本至9.0并优化仓库配置 - 修复布局文件中的重复元素和警告 - 增加构建警告修复文档 - 优化模拟器控制类功能
This commit is contained in:
BIN
mumu-pytest/__pycache__/conftest.cpython-313-pytest-8.3.4.pyc
Normal file
BIN
mumu-pytest/__pycache__/conftest.cpython-313-pytest-8.3.4.pyc
Normal file
Binary file not shown.
BIN
mumu-pytest/__pycache__/test_mumu.cpython-313-pytest-8.3.4.pyc
Normal file
BIN
mumu-pytest/__pycache__/test_mumu.cpython-313-pytest-8.3.4.pyc
Normal file
Binary file not shown.
@@ -100,6 +100,36 @@ class MumuEmulator:
|
||||
pyautogui.press("enter")
|
||||
print("按下回车")
|
||||
|
||||
def press_home(self):
|
||||
"""按 Home 键返回桌面"""
|
||||
pyautogui.press("home")
|
||||
print("按下 Home 键")
|
||||
|
||||
def right_click(self):
|
||||
"""右键点击"""
|
||||
pyautogui.rightClick()
|
||||
print("右键点击")
|
||||
|
||||
def wait_for_image(self, image_name, confidence=0.8, timeout=30):
|
||||
"""等待图片出现并返回位置"""
|
||||
image_path = os.path.join(self.script_dir, f"{image_name}.png")
|
||||
if not os.path.exists(image_path):
|
||||
print(f"图片不存在: {image_path}")
|
||||
return None
|
||||
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
location = pyautogui.locateOnScreen(image_path, confidence=confidence)
|
||||
if location:
|
||||
print(f"找到图片: {image_name}")
|
||||
return location
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(1)
|
||||
print(f"未找到图片: {image_name}")
|
||||
return None
|
||||
|
||||
def wait_for_boot(self, timeout=120):
|
||||
"""等待模拟器启动完成"""
|
||||
boot_completed = False
|
||||
@@ -126,7 +156,7 @@ class MumuEmulator:
|
||||
def run_sequence(self):
|
||||
"""按顺序执行任务"""
|
||||
self.bring_to_front()
|
||||
time.sleep(30)
|
||||
time.sleep(5)
|
||||
sequence = [
|
||||
"web",
|
||||
"web_address",
|
||||
@@ -141,7 +171,7 @@ class MumuEmulator:
|
||||
|
||||
for image_name in sequence:
|
||||
if image_name == "web_address":
|
||||
for _ in range(60):
|
||||
for _ in range(10):
|
||||
if self.check_image_exists("web_address"):
|
||||
time.sleep(1)
|
||||
self.type_text(WEB_URL)
|
||||
@@ -152,7 +182,7 @@ class MumuEmulator:
|
||||
else:
|
||||
print("web_address 图片不存在,跳过输入URL")
|
||||
else:
|
||||
self.find_and_click(image_name, timeout=60)
|
||||
self.find_and_click(image_name, timeout=10)
|
||||
time.sleep(2)
|
||||
|
||||
def close(self):
|
||||
@@ -161,6 +191,44 @@ class MumuEmulator:
|
||||
subprocess.run(["taskkill", "/F", "/IM", self.process_name])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def uninstall_app_ui(self):
|
||||
"""通过 UI 卸载 app:按 Home 键 -> 找到 flomo -> 右键 -> Uninstall -> Uninstall Confirm"""
|
||||
self.bring_to_front()
|
||||
time.sleep(2)
|
||||
|
||||
self.press_home()
|
||||
time.sleep(3)
|
||||
|
||||
location = self.wait_for_image("flomo", timeout=30)
|
||||
if not location:
|
||||
print("未找到 flomo 应用图标")
|
||||
return False
|
||||
|
||||
center = pyautogui.center(location)
|
||||
pyautogui.rightClick(center)
|
||||
time.sleep(1)
|
||||
|
||||
location = self.wait_for_image("uninstall", timeout=10)
|
||||
if not location:
|
||||
print("未找到 uninstall 选项")
|
||||
return False
|
||||
|
||||
center = pyautogui.center(location)
|
||||
pyautogui.click(center)
|
||||
time.sleep(1)
|
||||
|
||||
location = self.wait_for_image("uninstall-confirm", timeout=10)
|
||||
if not location:
|
||||
print("未找到卸载确认按钮")
|
||||
return False
|
||||
|
||||
center = pyautogui.center(location)
|
||||
pyautogui.click(center)
|
||||
time.sleep(2)
|
||||
|
||||
print("卸载完成")
|
||||
return True
|
||||
|
||||
|
||||
class AdbHelper:
|
||||
|
||||
BIN
mumu-pytest/flomo.png
Normal file
BIN
mumu-pytest/flomo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -57,3 +57,13 @@ def test_close_emulator(emulator):
|
||||
if emulator.is_running():
|
||||
emulator.close()
|
||||
assert not emulator.is_running(), "模拟器关闭失败"
|
||||
|
||||
|
||||
def test_uninstall_app(emulator):
|
||||
"""测试卸载 flomo app"""
|
||||
time.sleep(3)
|
||||
if not emulator.is_running():
|
||||
pytest.skip("模拟器未运行")
|
||||
|
||||
result = emulator.uninstall_app_ui()
|
||||
assert result, "卸载 app 失败"
|
||||
|
||||
BIN
mumu-pytest/uninstall-confirm.png
Normal file
BIN
mumu-pytest/uninstall-confirm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
mumu-pytest/uninstall.png
Normal file
BIN
mumu-pytest/uninstall.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Reference in New Issue
Block a user