qt4a.device Package¶
Android 设备模块
-
class
qt4a.device.AndroidDeviceResourceHandler(resource_lock_type=<class 'testbase.resource.LocalResourceLock'>)¶ 基类:
testbase.resource.LocalResourceHandler-
iter_resource(res_group=None, condition=None)¶ 遍历全部资源(可以按照优先级顺序返回来影响申请资源的优先级)
参数: - res_group (str) – 资源分组
- condition (dict) – 资源属性匹配
返回: iterator of resource, dict type with key ‘id’
Rtypes: iterator(dict)
-
-
class
qt4a.device.Device(id_or_adb_backend=None)¶ 基类:
objectAndroid设备类
-
add_phone_contacts(name, phone)¶ 添加手机联系人
-
check_netstat()¶ 检查网络状态
-
clear_camera_default_app()¶ 清除默认相机应用
-
clear_data(package_name)¶ 清理应用数据
参数: package_name (string) – 包名
-
clear_http_proxy()¶ 清除http代理
-
click(x, y)¶ 单击屏幕坐标
参数: - x (int/float) – 横坐标
- y (int/float) – 纵坐标
-
connect_vpn(vpn_type, server, username, password)¶ 连接VPN
参数: - vpn_type (string) – VPN类型
- server (string) – 服务器地址
- username (string) – 用户名
- password (string) – 密码
-
connect_wifi(wifi_name, wifi_pass='')¶ 连接指定的Wifi
参数: wifi_name (string) – WiFi名称
-
copy_file(src_path, dst_path)¶ 设备内复制文件
参数: - src_path (string) – 源路径
- dst_path (string) – 目标路径
-
country¶ 国家
-
cpu_type¶ cpu类型
-
current_activity¶ 当前Activity
-
debuggable¶ 是否是调试版系统
-
del_phone_contacts(name)¶ 删除手机联系人
-
delete_file(file_path)¶ 删除文件
参数: file_path (string) – 文件在设备中的路径
-
delete_folder(folder_path)¶ 删除文件夹
参数: folder_path (string) – 手机中的文件夹路径
-
device_host¶ 设备主机
-
device_id¶ 设备ID
-
disable_data_connection()¶ 禁用数据连接
-
disable_network()¶ 禁用所有网络
-
disable_wifi()¶ 禁用Wifi
-
disconnect_vpn()¶ 断开VPN
-
drag(x1, y1, x2, y2, count=5, wait_time=40, send_down_event=True, send_up_event=True)¶ 滑动
参数: - x1 (int) – 起始x坐标
- y1 (int) – 起始y坐标
- x2 (int) – 终止x坐标
- y2 (int) – 终止y坐标
- count (int) – 滑动的步数
- wait_time (int,单位:ms) – 每步间等待的时长
- send_down_event (bool) – 是否发送DOWN事件
- send_up_event (bool) – 是否发送UP事件
-
enable_network()¶ 启用任一网络,优先使用Wifi
-
enable_wifi()¶ 启用Wifi
-
end_call()¶ 挂断电话
-
static
extract_record_frame(file_path, save_dir)¶ 提取录屏文件中的帧
-
get_available_data_storage()¶ 获取数据存储区可用空间
-
get_available_external_storage()¶ 获取sdcard可用存储空间
-
get_clipboard_text()¶ 获取剪切板内容
-
get_current_activity()¶ 获取当前Activtiy
-
get_external_sdcard_path()¶ 获取外置SD卡路径
-
get_imei()¶ 获取设备imei号
-
get_phone_contacts()¶ 获取手机联系人列表
-
get_sim_card_state()¶ 获取sim卡状态
-
get_static_field_value(pkg_name, cls_name, field_name, field_type='')¶ 获取类中静态变量的值
参数: - pkg_name (string) – 包名
- cls_name (string) – 类名
- field_name (string) – 字段名
-
get_string_resource(pkg_name, string_id, lang='')¶ 获取字符串资源
-
get_string_resource_id(pkg_name, text)¶ 获取字符串资源ID
-
get_system_timezone()¶ 获取当前系统时区
-
grant_all_runtime_permissions(package_name)¶ 给APP授予所有运行时权限
-
has_camera()¶ 是否有摄像头
-
has_gps()¶ 是否有GPS
-
has_sim_card()¶ 是否有sim卡
-
imei¶ 手机串号
-
install_package(pkg_path, pkg_name='', overwrite=False)¶ 安装应用
参数: - pkg_path (string) – 安装包路径
- pkg_name (string) – 应用包名
- overwrite (bool) – 是否是覆盖安装
-
is_app_installed(app_name)¶ 应用是否安装
-
is_debug_package(package_name)¶ 是否是debug包
-
is_emulator_device()¶ 是否是模拟器设备
-
is_file_exists(file_path)¶ 判断文件或目录是否存在
参数: file_path (string) – 文件或目录在设备中的路径
-
is_rooted()¶ 是否root
-
kill_process(package_name)¶ 杀死进程
参数: package_name (string) – 应用包名
-
language¶ 语言
-
list_dir(dir_path)¶ 列取目录
-
lock_keyguard()¶ 锁屏
-
long_click(x, y, duration=1)¶ 长按屏幕坐标
参数: - x (int/float) – 横坐标
- y (int/float) – 纵坐标
- duration (int/float) – 按住时长,单位为秒
-
mkdir(dir_path)¶ 创建目录
参数: dir_path (string) – 要创建的目录路径
-
model¶ 设备型号
-
modify_hosts(new_hosts=[])¶ 修改hosts
参数: new_hosts (list) – 要修改的host列表,如果为空,表示恢复为默认hosts
-
play_sound(file_path, volume=50)¶ 播放语音
参数: file_path (string) – 音频文件路径
-
pull_dir(src_path, dst_path)¶ 从手机中拷贝文件夹到PC
参数: - src_path (string) – 手机上的源目录路径
- dst_path (string) – PC上的目的目录路径
-
pull_file(src_path, dst_path)¶ 将手机中的文件拷贝到PC中
参数: - src_path (string) – 手机中的源路径
- dst_path (string) – PC中的目的路径
-
push_dir(src_path, dst_path)¶ 向手机中拷贝文件夹
参数: - src_path (string) – PC上的源目录路径
- dst_path (string) – 手机上的目的目录路径
-
push_file(src_path, dst_path)¶ 向手机中拷贝文件
参数: - src_path (string) – PC上的源路径
- dst_path (string) – 手机上的目标路径
-
read_logcat(tag, process_name_pattern, pattern, num=1)¶ 查找最近满足条件的一条log
参数: - tag (string) – 期望的Tag
- process_name_pattern (string) – 期望的进程名,传入正则表达式
- pattern (Pattern) – 期望匹配的格式
- num (int) – 返回满足条件的日志条数
-
reboot(wait_cpu_low=True, usage=20, duration=10, timeout=120)¶ 重启手机
参数: - wait_cpu_low (bool) – 是否等待CPU使用率降低
- usage (int) – cpu使用率阈值
- duration (int) – 持续时间(秒)
- timeout (int) – 超时时间,超市时间到后,无论当前CPU使用率是多少,都会返回
-
record_screen(save_path, record_time, frame_rate=10, quality=20)¶ 录屏
参数: - save_path (string) – 保存路径,如果为已存在的目录路径,则会将每一帧图片保存到该目录下
- record_time – 录制时间,单位:秒
- frame_rate (int) – 帧率,1-30
- quality (int) – 压缩质量,10-100
-
refresh_media_store(file_path='')¶ 刷新图库,显示新拷贝到手机的图片
参数: file_path (string) – 要刷新的图片路径,不指定则刷新整个sdcard
-
register_screenshot_callback(callback, frame_rate=15)¶ 注册截图回调函数
参数: - callback (function) – 回调函数,回调参数为PIL的Image对象
- frame_rate (int) – 期望的帧率
-
static
release_all_device()¶ 释放所有设备
-
resolve_domain(domain)¶ 解析域名
-
run_as(package_name, cmd, **kwargs)¶ 以package_name权限执行命令cmd
参数: - package_name (string) – 包名,必须是已经安装的debug包
- cmd (string) – 命令行
-
run_shell_cmd(cmd, *args, **kwargs)¶ 执行adb shell命令
-
static
screen_frame_to_video(frame_list, frame_rate, save_path)¶ 将录屏帧序列转换为视频文件
-
screen_scale¶ 屏幕缩放比例
-
screen_size¶ 屏幕大小
-
sdk_version¶ SDK版本
-
send_file_to_app(activity, file_path)¶ 向app分享文件
-
send_image_to_app(activity, image_path)¶ 向app分享图片
-
send_key(key)¶ 发送按键
参数: key (string) – 按键
-
send_text(text)¶ 通过输入法方式发送文本
参数: text (string) – 要发送的文本
-
send_text_to_app(activity, text)¶ 向app分享文本
-
set_allow_unknown_app(allow=True)¶ 设置是否允许安装未知来源的应用
参数: allow (boolean) – 是否允许
-
set_app_permission(package_name, perm_name, is_allowed=True)¶ 设置应用权限
参数: - package_name (string) – 应用包名
- perm_name (string) – 权限名称
- is_allowed (bool) – 是否允许
-
set_auto_rotate_screen(rotate=False)¶ 设置是否旋转屏幕
参数: rotate (boolean) – 是否旋转
-
set_camera_photo(pic_path)¶ 设置相机图片,调用该接口后,调用相机接口会返回指定图片
参数: pic_path (String) – 图片在PC中的路径
-
set_clipboard_text(text)¶ 设置剪贴板内容
-
set_default_app(action, type, new_app)¶ 设置默认应用
参数: - action (String) – 应用针对的类型,如:android.media.action.IMAGE_CAPTURE
- new_app (String) – 新的应用包名
-
set_default_input_method(input_method)¶ 设置默认输入法
参数: input_method (string) – 要设置的输入法服务名(package_name/service_name)
-
set_default_language(lang)¶ 设置默认语言
-
set_http_proxy(host, port)¶ 设置http代理
参数: - host – 代理服务器地址
- port – 代理服务器端口
-
set_radio_enabled(enable)¶ 是否启用Radio
-
set_screen_off_time(timeout=600)¶ 设置灭屏时间
参数: timeout (int,单位为秒) – 超时时间
-
set_system_time(new_time=None)¶ 设置系统时间
参数: new_time (str) – 新时间,默认为PC上的时间,格式为: 20151001.170000
-
set_system_timezone(new_timezone='Asia/Shanghai')¶ 修改系统时区
-
set_time_12_24(is_24=True)¶ 设置12/24小时格式
参数: is_24 (boolean) – 是否是24小时
-
set_volume(volume)¶ 设置音量
-
start_activity(activity_name, action='', type='', data_uri='', extra={}, wait=True)¶ 启动activity
参数: - activity_name (string) – Activity名称,如:com.tencent.mobileqq/.activity.SplashActivity
- action (string) – Action名称
- type (string) – mime类型
- data_uri (string) – data uri
- extra (dict) – 额外参数
- wait (boolean) – 是否等待启动完成
-
switch_to_data_connection()¶ 关闭WIFI,启用数据连接
-
system_version¶ 系统版本
-
take_screen_shot(save_path)¶ 截屏
参数: save_path (string) – 截屏图片存放在PC上的路径
-
uninstall_package(pkg_name)¶ 卸载应用
参数: pkg_name (string) – 包名
-
unlock_keyguard()¶ 解锁屏幕
-
unregister_screenshot_callback(callback)¶ 注销截图回调函数
参数: callback (function) – 回调函数
-
wake_screen(wake=True)¶ 唤醒屏幕
-