Appium基础API

获取app的包名和启动名:

print(driver.current_package)
print(driver.current_activity)  

在脚本内启动其他app:

driver.start_activity('包名','启动名')

关闭app:

driver.close_app()#关闭当前操作的app,不会关闭驱动对象

关闭驱动对象:

driver.quit()#关闭驱动对象,同时关闭所关联的app

安装apk到手机(Android):

driver.install_app(app_path)

手机中移除app:

driver.remove_app(app_id)#app_id 包名

判断app是否安装:

print(driver.is_app_installed(app_id))

发送文件到手机:

import base64
'''python3.x中字符都为Unicode编码,用b64encode函数的参数为byte类型,
需要先转码,生成的数据为byte类型,需要将byte转换回去。
参数:
path,手机设备上的路径
data,文件内数据,要求base64编码
'''
date = str(base64.b64encode(data.encode('utf-8')),'utf-8')
driver.push_file(path,data)

从手机中拉去文件:

import base64

date = driver.pull_file(path)#返回数据为base64编码,path是手机设备上的路径
print(str(base64.b64encode(data),'utf-8'))#base64编码

获取当前屏幕内元素结构:

print(driver.page_source)#打印出当前页面元素结构

  输出后可以进行XML格式化,具体使用的较少,有时会用于查找不显示在屏幕上而代码中有的字样。

应用置于后台事件:

driver.background_app(5)#至于后台5秒,再次展示当前页面,实际时间会长一点

待更新

猜你喜欢

转载自www.cnblogs.com/yuntimer/p/12547444.html
今日推荐