import os
from selenium import webdriver
# 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['device'] = 'Android'
desired_caps['browserName'] = ''
desired_caps['version'] = '4.2'
desired_caps['app'] = PATH('C:\Users\miting\Downloads\ContactManager.apk')
desired_caps['app-package'] = 'com.example.android.contactmanager'
desired_caps['app-activity'] = '.ContactManager'
driver = webdriver.Remote('http://localhost:8888/wd/hub', desired_caps)
print 1
el = driver.find_element_by_name("Add Contact")
el.click()
textfields = driver.find_elements_by_tag_name("textfield")
textfields[0].send_keys("My Name")
textfields[2].send_keys("someone@somewhere.com")
driver.find_element_by_name("Save").click()
driver.quit()
在真机上跑一个例子,结果出现了如下的提示。
Traceback (most recent call last):
File "D:\eclipse\workspace\appiumtest\src\com\appium\test\test1.py", line 30, in <module>
driver = webdriver.Remote('http://localhost:8888/wd/hub', desired_caps)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 72, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 115, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 166, in execute
self.error_handler.check_response(response)
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: Parameter 'appPackage' is required for launching application)"
然后我将 desired_caps['app-package'] 修改为 desired_caps['appPackage'] ,desired_caps['app-activity'] 修改为 desired_caps['appActivity'],便可以运行了。我的 appium 版本是 Welcome to Appium v1.0.0-beta.1,我很好奇到底是为什么?新版本改动?如果是新版本改动的话,那我又该如何查看详情呢?还望高手指点