airtest.core.android.android module¶
-
class
Android
(serialno=None, host=None, cap_method='MINICAP', touch_method='MINITOUCH', ime_method='YOSEMITEIME', ori_method='MINICAPORI', display_id=None, input_event=None)[源代码]¶ -
Android Device Class
-
touch_proxy
¶ 根据self.touch_method的类型,执行对应的触摸操作
Module:
airtest.core.android.touch_methods.touch_proxy.TouchProxy
返回: TouchProxy 实际案例
>>> dev = Android() >>> dev.touch_proxy.touch((100, 100)) # If the device uses minitouch, it is the same as dev.minitouch.touch >>> dev.touch_proxy.swipe_along([(0,0), (100, 100)])
-
touch_method
¶ In order to be compatible with the previous dev.touch_method
为了兼容以前的`dev.touch_method`
返回: “MINITOUCH” or “MAXTOUCH” 实际案例
>>> dev = Android() >>> print(dev.touch_method) # "MINITOUCH"
-
cap_method
¶ In order to be compatible with the previous dev.cap_method
为了兼容以前的`dev.cap_method`
返回: “MINICAP” or “JAVACAP” 实际案例
>>> dev = Android() >>> print(dev.cap_method) # "MINICAP"
-
screen_proxy
¶ Similar to touch_proxy, it returns a proxy that can automatically initialize an available screenshot method, such as Minicap
Afterwards, you only need to call
self.screen_proxy.get_frame()
to get the screenshot类似touch_proxy,返回一个代理,能够自动初始化一个可用的屏幕截图方法,例如Minicap
后续只需要调用 ``self.screen_proxy.get_frame()``即可获取到屏幕截图
Returns: ScreenProxy(Minicap())
实际案例
>>> dev = Android() >>> img = dev.screen_proxy.get_frame_from_stream() # dev.minicap.get_frame_from_stream() is deprecated
-
get_deprecated_var
(old_name, new_name)[源代码]¶ Get deprecated class variables
When the airtest version number>=1.1.2, the call device.minicap/device.javacap is removed, and relevant compatibility is made here, and DeprecationWarning is printed
airtest版本号>=1.1.2时,去掉了device.minicap/device.javacap这样的调用,在此做了相关的兼容,并打印DeprecationWarning
Usage: Android.minicap=property(lambda self: self.get_deprecated_var(“minicap”, “screen_proxy”))
参数: - old_name – “minicap”
- new_name – “screen_proxy”
返回: New implementation of deprecated object, e.g self.minicap -> self.screen_proxy
dev.minicap.get_frame_from_stream() -> dev.screen_proxy.get_frame_from_stream()
实际案例
>>> dev = Android() >>> isinstance(dev.minicap, ScreenProxy) # True >>> dev.minicap.get_frame_from_stream() # --> dev.screen_proxy.get_frame_from_stream()
-
uuid
¶ Serial number
返回:
-
check_app
(package)[源代码]¶ 检查package在设备中是否存在
参数: package – package name 返回: 如果存在,返回True Raises: AirtestError
– raised if package is not found
-
start_app
(package, activity=None)[源代码]¶ 启动应用
参数: - package – package name
- activity – activity name
返回: None
-
start_app_timing
(package, activity)[源代码]¶ 启动应用,并且返回启动耗费时间
参数: - package – package name
- activity – activity name
返回: app启动时间
-
install_app
(filepath, replace=False, install_options=None)[源代码]¶ 将应用安装到手机上
参数: - filepath – apk 文件在PC上的完整路径
- replace – 如果应用已存在,是否替换
- install_options – install命令的额外选项,默认是[]
返回: 安装进程的输出内容
-
install_multiple_app
(filepath, replace=False, install_options=None)[源代码]¶ Install multiple the application on the device
参数: - filepath – apk 文件在PC上的完整路径
- replace – 如果应用已存在,是否替换
- install_options – install命令的额外选项,默认是[]
返回: 安装进程的输出内容
-
snapshot
(filename=None, ensure_orientation=True, quality=10, max_size=None)[源代码]¶ 截取一张当前手机画面,默认会发送到stdout
参数: - filename – 保存截图的文件名,默认为None的话将会发送到stdout
- ensure_orientation – 截图方向是否要与当前显示情况一致,默认为True
- quality – The image quality, integer in range [1, 99]
- max_size – the maximum size of the picture, e.g 1200
返回: 截图输出
-
shell
(*args, **kwargs)[源代码]¶ 返回 adb shell 解释器
参数: - *args – optional shell commands
- **kwargs – optional shell commands
返回: None
-
keyevent
(keyname, **kwargs)[源代码]¶ 在设备上执行keyevent
参数: - keyname – keyevent name
- **kwargs – optional arguments
返回: None
-
text
(text, enter=True, **kwargs)[源代码]¶ 向设备中输入字符串
参数: - text – 要输入的字符串
- enter – 是否按下`Enter`键
- search – 是否要按下输入法键盘中的search键
返回: None
-
swipe
(p1, p2, duration=0.5, steps=5, fingers=1)[源代码]¶ 在设备上执行滑动操作
参数: - p1 – 开始坐标
- p2 – 结束坐标
- duration – 在屏幕上滑动的时长,默认是0.5
- steps – 滑动过程中的步数,默认为5
- fingers – 滑动的手指数量,1或者2,默认为1
返回: None
-
pinch
(center=None, percent=0.5, duration=0.5, steps=5, in_or_out='in')[源代码]¶ 在设备上执行pinch操作(放大缩小),仅适用于minitouch和maxtouch
参数: - center – pinch操作的中心点
- percent – pinch操作捏合屏幕的距离,默认是0.5
- duration – 滑动过程中的时间间隔,默认是0.8
- steps – 滑动过程中的步数,默认为5
- in_or_out – 向内捏合in或者向外捏合out,默认是’in’
返回: None
Raises: TypeError
– An error occurred when center is not a list/tuple or None
-
swipe_along
(coordinates_list, duration=0.8, steps=5)[源代码]¶ 执行一段连续的滑动操作,仅适用于minitouch和maxtouch
参数: - coordinates_list – 一个坐标的列表:[(x1, y1), (x2, y2), (x3, y3)]
- duration – 滑动过程中的时间间隔,默认是0.8
- steps – 滑动过程中的步数,默认为5
返回: None
-
two_finger_swipe
(tuple_from_xy, tuple_to_xy, duration=0.8, steps=5, offset=(0, 50))[源代码]¶ 执行两个手指一起滑动的操作,仅适用于minitouch和maxtouch
参数: - tuple_from_xy – 开始坐标
- tuple_to_xy – 结束坐标
- duration – 滑动过程中的时间间隔,默认是0.8
- steps – 滑动过程中的步数,默认为5
- offset – 第二个手指相对于第一个手指的偏移坐标,默认是(0, 50)
返回: None
-
logcat
(*args, **kwargs)[源代码]¶ 执行 logcat
参数: - *args – optional arguments
- **kwargs – optional arguments
返回: logcat 输出
-
getprop
(key, strip=True)[源代码]¶ 根据传入的key获取properties内容
参数: - key – key name
- strip – 是否对输出内容进行strip
返回: property value(s)
-
get_ip_address
()[源代码]¶ 执行以下几种命令行来获取IP地址
- adb shell netcfg | grep wlan0
- adb shell ifconfig
- adb getprop dhcp.wlan0.ipaddress
返回: 如果获取IP失败,返回None,否则返回IP地址
-
display_info
¶ 返回显示信息(width, height, orientation 和 max_x, max_y)
返回: 显示信息
-
get_render_resolution
(refresh=False)[源代码]¶ 返回旋转后的渲染分辨率
参数: refresh – 是否强制刷新渲染分辨率 返回: offset_x, offset_y, offset_width and offset_height of the display
-
start_recording
(max_time=1800, bit_rate_level=1, bit_rate=None)[源代码]¶ 开始对设备画面进行录制
参数: - max_time – maximum screen recording time, default is 1800
- bit_rate_level – bit_rate=resolution*level, 0 < level <= 5, default is 1
- bit_rate – the higher the bitrate, the clearer the video
返回: None
实际案例
Record 30 seconds of video and export to the current directory test.mp4:
>>> from airtest.core.api import connect_device, sleep >>> dev = connect_device("Android:///") >>> # Record the screen with the lowest quality >>> dev.start_recording(bit_rate_level=1) >>> sleep(30) >>> dev.stop_recording(output="test.mp4")
Or set max_time=30, the screen recording will stop automatically after 30 seconds:
>>> dev.start_recording(max_time=30, bit_rate_level=5) >>> dev.stop_recording(output="test_30s.mp4")
The default value of max_time is 1800 seconds, so the maximum screen recording time is half an hour. You can modify its value to obtain a longer screen recording:
>>> dev.start_recording(max_time=3600, bit_rate_level=5) >>> dev.stop_recording(output="test_hour.mp4")
-
stop_recording
(output='screen.mp4', is_interrupted=False)[源代码]¶ 停止对设备画面的录制。录制出的文件将会放在设备中。
参数: - output – default file is screen.mp4
- is_interrupted – True or False. Stop only, no pulling recorded file from device.
返回: None
-
javacap
¶
-
maxtouch
¶
-
minicap
¶
-
minitouch
¶
-