真机上已经调用如下类方法进行了安装 app
class installApp():
''' 安装app '''
def installAndroidApp(self):
''' 定义安装app函数--安卓 '''
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p))
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.3'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH(r'G:\workspace\src\common\testApp\testApp.apk')
desired_caps['app-Package'] = 'com.android.test'
desired_caps['app-Activity'] = '.test'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(2)
return driver
执行下一个用例的时候,也需要使用 driver 的属性方法,可是不能再调用上面的函数了,因为调用还是会再次安装 app,
请问:如何在不安装 app 的情况下,获取 driver 的属性方法呢?
查询了下资料,说是将
desired_caps['app'] = PATH(r'G:\workspace\src\common\testApp\testApp.apk')
代码注释掉,不过我试了,注释掉上面这行后,依然报错:
#!/usr/bin/env python
# -*- encoding:UTF-8 -*-
from appium import webdriver
import time,os
class getDriverInfo():
''' 获取driver属性信息的类 '''
def androidDriverInfo(self):
''' 定义获取driver属性信息的函数--安卓 '''
# Returns abs path relative to this file and not cwd
#PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p))
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.3'
desired_caps['deviceName'] = 'Android Emulator'
#desired_caps['app'] = PATH(r'G:\workspace\src\common\testApp\testApp.apk')
desired_caps['app-Package'] = 'com.android.test'
desired_caps['app-Activity'] = '.test'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(2)
return driver
if __name__ == '__main__':
driverInfo = getDriverInfo()
app = driverInfo.androidDriverInfo()
print app.contexts()
报错的信息如下:
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u"A new session could not be created. (Original error: No app set; either start appium with --app or pass in an 'app' value in desired capabilities, or set androidPackage to launch pre-existing app on device)"
请问大家是如何解决执行测试用例的时候,不要每次都重新安装 apk ,就可以获取 driver 属性信息的?