openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.18k stars 1.35k forks source link

BUG: capture_screen returns incomplete images #975

Closed agctute closed 1 month ago

agctute commented 1 month ago

请务必提供详细的信息,能够复现你的问题,否则很难帮你解决。没用的Issue将自动被机器人打上Invalid标签并且自动关闭!!。

Sometimes when capturing the screen, the image is incomplete, as shown above.

codeskyblue commented 1 month ago

3.x is fine which is using screencap instead of minicap ---- Replied Message ---- FromCharles @.>Date05/16/2024 15:42 @.> @.>Subject[openatx/uiautomator2] BUG: capture_screen returns incomplete images (Issue #975) 请务必提供详细的信息,能够复现你的问题,否则很难帮你解决。没用的Issue将自动被机器人打上Invalid标签并且自动关闭!!。 手机型号: Nexus 4, API 31, Android 12 uiautomator2的版本号: 2.16.26 手机截图 相关日志(Python控制台错误信息, adb logcat完整信息, atxagent.log日志) 最好能附上可能复现问题的代码。 from infra import AndroidController from pathlib import Path import subprocess from config import apk_info import cv2 def get_connected_devices(): output = subprocess.check_output(['adb', 'devices']).decode('utf-8') devices = [line.split('\t')[0] for line in output.splitlines()[1:] if line.strip()] return devices def get_only_device(): devices = get_connected_devices() if not devices: return None if len(devices) > 1: return None return devices[0] port = get_only_device() apk_name = input("\nEnter apk name (do not include '.apk'):\n") apk_path = apk_info[apk_name]['path'] package = apk_info[apk_name]['package'] username = apk_info[apk_name]['username'] password = apk_info[apk_name]['password'] controller = AndroidController(port, package) trace_dir = Path("test") / apk_name trace_dir.mkdir(parents=True, exist_ok=True) activities = [] index = 0 while True: input("\nPress Enter to capture screen and dump hierarchy.") screenshot = controller.capture_screen() hierarchy_str = controller.dumpstr() ui_hierarchy = controller.dump() activity = controller.activity() activities.append(activity.info()) cv2.imwrite(str(trace_dir / f"{index}.png"), screenshot) with open(trace_dir / f"{index}.xml", 'w', encoding="utf-8") as f: f.write(hierarchy_str) index += 1 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>