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)[source]¶ Bases:
airtest.core.device.Device
Android Device Class
-
touch_proxy
¶ Perform touch operation according to self.touch_method
Module:
airtest.core.android.touch_methods.touch_proxy.TouchProxy
Returns: TouchProxy Examples
>>> 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`
Returns: “MINITOUCH” or “MAXTOUCH” Examples
>>> dev = Android() >>> print(dev.touch_method) # "MINITOUCH"
-
cap_method
¶ In order to be compatible with the previous dev.cap_method
为了兼容以前的`dev.cap_method`
Returns: “MINICAP” or “JAVACAP” Examples
>>> 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())
Examples
>>> 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)[source]¶ 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”))
Parameters: - old_name – “minicap”
- new_name – “screen_proxy”
Returns: 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()
Examples
>>> dev = Android() >>> isinstance(dev.minicap, ScreenProxy) # True >>> dev.minicap.get_frame_from_stream() # --> dev.screen_proxy.get_frame_from_stream()
-
get_default_device
()[source]¶ Get local default device when no serialno
Returns: local device serialno
-
uuid
¶ Serial number
Returns:
-
list_app
(third_only=False)[source]¶ Return list of packages
Parameters: third_only – if True, only third party applications are listed Returns: array of applications
-
path_app
(package)[source]¶ Print the full path to the package
Parameters: package – package name Returns: the full path to the package
-
check_app
(package)[source]¶ Check if package exists on the device
Parameters: package – package name Returns: True if package exists on the device Raises: AirtestError
– raised if package is not found
-
start_app
(package, activity=None)[source]¶ Start the application and activity
Parameters: - package – package name
- activity – activity name
Returns: None
-
start_app_timing
(package, activity)[source]¶ Start the application and activity, and measure time
Parameters: - package – package name
- activity – activity name
Returns: app launch time
-
clear_app
(package)[source]¶ Clear all application data
Parameters: package – package name Returns: None
-
install_app
(filepath, replace=False, install_options=None)[source]¶ Install the application on the device
Parameters: - filepath – full path to the apk file to be installed on the device
- replace – True or False to replace the existing application
- install_options – list of options, default is []
Returns: output from installation process
-
install_multiple_app
(filepath, replace=False, install_options=None)[source]¶ Install multiple the application on the device
Parameters: - filepath – full path to the apk file to be installed on the device
- replace – True or False to replace the existing application
- install_options – list of options, default is []
Returns: output from installation process
-
uninstall_app
(package)[source]¶ Uninstall the application from the device
Parameters: package – package name Returns: output from the uninstallation process
-
snapshot
(filename=None, ensure_orientation=True, quality=10, max_size=None)[source]¶ Take the screenshot of the display. The output is send to stdout by default.
Parameters: - filename – name of the file where to store the screenshot, default is None which is stdout
- ensure_orientation – True or False whether to keep the orientation same as display
- quality – The image quality, integer in range [1, 99]
- max_size – the maximum size of the picture, e.g 1200
Returns: screenshot output
-
shell
(*args, **kwargs)[source]¶ Return adb shell interpreter
Parameters: - *args – optional shell commands
- **kwargs – optional shell commands
Returns: None
-
keyevent
(keyname, **kwargs)[source]¶ Perform keyevent on the device
Parameters: - keyname – keyevent name
- **kwargs – optional arguments
Returns: None
-
text
(text, enter=True, **kwargs)[source]¶ Input text on the device
Parameters: - text – text to input
- enter – True or False whether to press Enter key
- search – True or False whether to press Search key on IME after input
Returns: None
-
touch
(pos, duration=0.01)[source]¶ Perform touch event on the device
Parameters: - pos – coordinates (x, y)
- duration – how long to touch the screen
Returns: None
-
swipe
(p1, p2, duration=0.5, steps=5, fingers=1)[source]¶ Perform swipe event on the device
Parameters: - p1 – start point
- p2 – end point
- duration – how long to swipe the screen, default 0.5
- steps – how big is the swipe step, default 5
- fingers – the number of fingers. 1 or 2.
Returns: None
-
pinch
(center=None, percent=0.5, duration=0.5, steps=5, in_or_out='in')[source]¶ Perform pinch event on the device, only for minitouch and maxtouch
Parameters: - center – the center point of the pinch operation
- percent – pinch distance to half of screen, default is 0.5
- duration – time interval for swipe duration, default is 0.8
- steps – size of swipe step, default is 5
- in_or_out – pinch in or pinch out, default is ‘in’
Returns: None
Raises: TypeError
– An error occurred when center is not a list/tuple or None
-
swipe_along
(coordinates_list, duration=0.8, steps=5)[source]¶ Perform swipe event across multiple points in sequence, only for minitouch and maxtouch
Parameters: - coordinates_list – list of coordinates: [(x1, y1), (x2, y2), (x3, y3)]
- duration – time interval for swipe duration, default is 0.8
- steps – size of swipe step, default is 5
Returns: None
-
two_finger_swipe
(tuple_from_xy, tuple_to_xy, duration=0.8, steps=5, offset=(0, 50))[source]¶ Perform two finger swipe action, only for minitouch and maxtouch
Parameters: - tuple_from_xy – start point
- tuple_to_xy – end point
- duration – time interval for swipe duration, default is 0.8
- steps – size of swipe step, default is 5
- offset – coordinate offset of the second finger, default is (0, 50)
Returns: None
-
logcat
(*args, **kwargs)[source]¶ Perform `logcat`operations
Parameters: - *args – optional arguments
- **kwargs – optional arguments
Returns: logcat output
-
getprop
(key, strip=True)[source]¶ Get properties for given key
Parameters: - key – key name
- strip – True or False whether to strip the output or not
Returns: property value(s)
-
get_ip_address
()[source]¶ Perform several set of commands to obtain the IP address
- adb shell netcfg | grep wlan0
- adb shell ifconfig
- adb getprop dhcp.wlan0.ipaddress
Returns: None if no IP address has been found, otherwise return the IP address
-
is_keyboard_shown
()[source]¶ Return True or False whether soft keyboard is shown or not
Notes
Might not work on all devices
Returns: True or False
-
is_screenon
()[source]¶ Return True or False whether the screen is on or not
Notes
Might not work on all devices
Returns: True or False
-
is_locked
()[source]¶ Return True or False whether the device is locked or not
Notes
Might not work on some devices
Returns: True or False
-
display_info
¶ Return the display info (width, height, orientation and max_x, max_y)
Returns: display information
-
get_display_info
()[source]¶ Return the display info (width, height, orientation and max_x, max_y)
Returns: display information
-
get_current_resolution
()[source]¶ Return current resolution after rotation
Returns: width and height of the display
-
get_render_resolution
(refresh=False)[source]¶ Return render resolution after rotation
Parameters: refresh – whether to force refresh render resolution Returns: offset_x, offset_y, offset_width and offset_height of the display
-
start_recording
(max_time=1800, bit_rate_level=1, bit_rate=None)[source]¶ Start recording the device display
Parameters: - 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
Returns: None
Examples
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)[source]¶ Stop recording the device display. Recoding file will be kept in the device.
Parameters: - output – default file is screen.mp4
- is_interrupted – True or False. Stop only, no pulling recorded file from device.
Returns: None
-
javacap
¶
-
maxtouch
¶
-
minicap
¶
-
minitouch
¶
-