锁屏
self.driver.lock() # ---锁定屏幕(无限期锁定)self.driver.lock(秒数) # ---锁定屏幕(锁定固定秒数后自动解锁)self.driver.unlock() # ---解锁屏幕self.driver.is_locked() # ---判断屏幕是否已经被锁定,返回值是布尔值
输入法
self.driver.deactivate_ime_engine() # 关闭当前输入法,会自动切换到安卓系统自带的输入法(.LatinIME)self.driver.is_ime_active() # 返回是否有输入法服务的布尔值。self.driver.available_ime_engines # 获得所有可用的输入法(引擎),返回一个列表,包含所有输入法引擎的字符串。self.driver.active_ime_engine # 获得正在使用的一个输入法(当前输入法)self.driver.activate_ime_engine("某一种输入法引擎") # 切换当前输入法为目标输入法
设备
driver.quit()# 执行时,关闭DesiredCapabilities里所指定的目标App,不关闭其他App,结束与服务器的连接会话。
屏幕
# 获取屏幕状态orientation = driver.orientation# LANDSCAPE 代表横屏 # PORTRAIT 代表竖屏# 设置横竖屏driver.orientation = "LANDSCAPE" #设置为横屏driver.orientation = "PORTRAIT" #设置为竖屏
地理坐标
# 设置地理坐标driver.set_location(x, y, h)参数:纬度-x number 所需的地理位置纬度经度-y number 所需的地理位置经度高度-h number 所需的地理位置高度(可选)# 获取当前地理坐标location=driver.location() # {'latitude': 50, 'longitude': 122, 'altitude': 8}
导入文件
import base64# 目标文件路径dest_path = '/data/local/tmp/test_push_file.txt'# 文本中的内容和编码格式data = bytes('This is the contents of the file to push to the device.', 'utf-8')# 向目标路径导入文件driver.push_file(dest_path, base64.b64encode(data).decode('utf-8'))# 完成后结果C:\Users\lgq>adb shellvbox86p:/ # cd /data/local/tmp/vbox86p:/data/local/tmp # ls# appium_cache test_push_file.txt uidump.xmlvbox86p:/data/local/tmp # cat test_push_file.txt# This is the contents of the file to push to the device.vbox86p:/data/local/tmp #
获取文件
driver.pull_file('/data/local/tmp/test_push_file.txt')# ntYDG7Doz6+KfZpdepkGSjymTz/yysyDq2AaYzOLRPFtPZu0qQFBRpkMOxtWUabAuHb/IMngcSN0y4xaqaS+zUYnfj5lOGxizGTMAVuijc53Z
获取文件夹
driver.pull_folder('/data/local/tmp/')
通知栏
driver.open_notifications() # 无参,自动打开通知栏
开关WiFi
driver.toggle_wifi() #当前开执行切换为关,当前关执行切换为开
开关定位
driver.toggle_location_services() #当前开执行切换为关,当前关执行切换为开
发送短信(仅模拟器)
driver.send_sms('17615146641', 'Hey')# 如果报错:sms method is only available for emulators # 说明你不是模拟器
打电话(仅模拟器)
from appium.webdriver.extensions.android.gsm import GsmCallActionsdriver.make_gsm_call('5551234567', GsmCallActions.CALL)# 如果报错:gsmCall method is only available for emulators# 说明你不是模拟器