AirtestProject / AirtestProject/Airtest

关于snapshot是否支持多屏的问题

未关闭
#427 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
9.6k
派生
1.5k
PR 合并指标
30 天内没有已合并 PR

描述

**描述问题**
我们当前在一个比较特殊的安卓设备中尝试使用Airtest的API,该设备比较特殊,Android系统是多屏输出(有显示屏1和显示屏2)。我们在连接设备的时候选择的cap_method是adbcap,当我们调用API的snapshot方法时,该方法只能截取显示屏1的信息,因此为了适配我们自己的测试场景(能让用户自己选择截取显示屏1或者2),我们基于Airtest的API封装了自己的API,并且改写了snapshot方法:
```python
def _snap_shot(dev, filename=None, ensure_orientation=True, screen_idx=0):
"""default not write into file."""
if dev.cap_method == CAP_METHOD.MINICAP_STREAM:
dev.rotation_watcher.get_ready()
screen = dev.minicap.get_frame_from_stream()
elif dev.cap_method == CAP_METHOD.MINICAP:
screen = dev.minicap.get_frame()
elif dev.cap_method == CAP_METHOD.JAVACAP:
screen = dev.javacap.get_frame_from_stream()
else:
# screen = dev.adb.snapshot()
screen = _adb_snap_shot(dev.adb, screen_idx)
# output cv2 object
try:
screen = aircv.utils.string_2_img(screen)
except Exception:
# may be black/locked screen or other reason, print exc for debugging
import traceback
traceback.print_exc()
return None

# ensure the orientation is right
if ensure_orientation and dev.display_info["orientation"]:
# minicap screenshots are different for various sdk_version
if dev.cap_method in (CAP_METHOD.MINICAP, CAP_METHOD.MINICAP_STREAM) and dev.sdk_version <= 16:
h, w = screen.shape[:2] # Hight is in the front for cvshape!!!!
if w < h: # For devices with sdk<=16, will rotate if the picture is upright when screen is landscape
screen = aircv.rotate(screen, dev.display_info["orientation"] * 90, clockwise=False)
# No extra rotation if sdk>=25(Android7.1 and above) for adb snapshot
elif dev.cap_method == CAP_METHOD.ADBCAP and dev.sdk_version <= SDK_VERISON_NEW:
screen = aircv.rotate(screen, dev.display_info["orientation"] * 90, clockwise=False)
if filename:
aircv.imwrite(filename, screen)
return screen

def _adb_snap_shot(adb, screen_idx=0):
cmd_screencap = "shell screencap -p -d " + str(screen_idx)
print("cmd_screencap: {0}".format(cmd_screencap))
raw = adb.cmd(cmd_screencap, ensure_unicode=False)
return raw.replace(adb.line_breaker, b"\n")
```

请问,在Airtest后续的版本中,有计划在snapshot中支持选择不同屏幕么?除了screencap,还有minicap

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。