今天是迈开腿得第二步,捋了一遍appium得API,没有丝毫顺序可言,我就根据自己的整理,想到啥写点啥吧,今天试试安装和卸载。
好嘞~上菜!!!
Install the application found at `app_path` on the device.
:Args:
- app_path - the local or remote path to the application to install
API大概的意思:通过给予的路劲,安装app
先看一下,我准备的apk安装包:
一共准备了三个安装包,‘test1’是一个低版本的app,‘test2’是一个高版本的app,‘kuaiya411’就是‘快牙’app。那么我准备的‘test1’和‘test2’除了版本号,有啥区别呢?
test1:
输入法会遮挡住‘登录按钮’
test2:
新版的不会遮挡‘登录按钮’
我们先装好低版本‘test1’,然后覆盖安装‘test2’。
执行代码
driver.install_app('D:/a/test2.apk')
执行结果:我就慌了~~~装完之后,没有改动,还是之前的test1,这是什么鬼~~
于是我手动安装了test2,然后尝试用API安装test1.(理论上来讲就是用手动肯定也装不上test1)
执行代码
driver.install_app('D:/a/test1.apk')
执行结果:跟实际预期一样,没变化。
难道是API用错了?我尝试装一个毫不相关的app试试。
执行代码
driver.install_app('D:/a/Kuaiya411.apk')
执行结果:这次装上了。
成功安装,看来这个命令只能用来安装,覆盖这个事貌似做不了,以后再深入探究一下吧。
2.is_app_installed(self, bundle_id)
Checks whether the application specified by `bundle_id` is installed on the device.
:Args:
- bundle_id - the id of the application to query
API大概意思是:检查指定的包,是否安装。返回True/False
这个API使用的时候,需要给他一个包名,那么怎么获取包名呢?我这有一个最笨的方法,先运行一下app,然后到'设置->应用->正在运行的应用->查看你的app->寻找进程中com.开头的一段英文',我用快牙给大伙截个图,大概是这个样子:
最笨的方法了~
显然,现在我已经装了’快牙‘,我们试试API的效果
执行代码
a = driver.is_app_installed('com.dewmobile.kuaiya')
print(a)
执行结果:True
3.remove_app(self, app_id)
Remove the specified application from the device.
:Args:
- app_id - the application id to be removed
API大概意思是:卸载
没啥好啰嗦的直接试试就行了,结合一下第二个API,我们看看结果。
执行代码
driver.remove_app('com.dewmobile.kuaiya')
a = driver.is_app_installed('com.dewmobile.kuaiya')
print(a)
执行结果:False
菜齐了~