Appium 是否版本问题

miting · 2014年04月22日 · 最后由 万万 回复于 2016年11月08日 · 2797 次阅读
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,我很好奇到底是为什么?新版本改动?如果是新版本改动的话,那我又该如何查看详情呢?还望高手指点

共收到 13 条回复 时间 点赞

这只是其中的一个 change 而已。具体改动文档还没能提现到,不知道他们什么时候更新文档。

#1 楼 @lihuazhang 好的,多谢了。找到了,的确是,看来我不应该用 npm install -g appium

Android

fix bug with XML page source where it wouldn't create the dump file correctly
change caps with hyphens (-) like "app-package" to be camelCased like the rest of Appium caps, e.g., "appPackage"
fix bug with custom keystore apk signing
allow multi actions without an element

1.0 确实改了.还是先用 0.18 得了

#3 楼 @cy_suncheng 我想请问下,0.18 是怎么安装的呢,我用 npm install appium@0.18.1 安装不成功

#4 楼 @miting 命令是这样 npm install -g appium,如果还是不成功,那就直接用 exe 的好了

#6 楼 @cy_suncheng 好的 多谢

现在 Sample-Code 里还是 app-package 和 app-activity

官方已经更新了文档, 这几点变动已经进行了说明

我的测试代码 from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2.2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

运行后的错误提示,请高手帮我看看,谢谢
C:\Python27\python.exe D:/pythonproject/s2.py
Traceback (most recent call last):
File "D:/pythonproject/s2.py", line 9, in
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
File "build\bdist.win32\egg\appium\webdriver\webdriver.py", line 35, in init
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 73, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 121, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 170, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 347, in execute
return self._request(command_info[0], url, body=data)
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 415, in _request
resp = opener.open(request)
File "C:\Python27\lib\urllib2.py", line 404, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 422, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1214, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1187, in do_open
r = h.getresponse(buffering=True)
File "C:\Python27\lib\httplib.py", line 1045, in getresponse
response.begin()
File "C:\Python27\lib\httplib.py", line 409, in begin
version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 373, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''

为什么 在官网上 代码是
from appium import webdriver 很多人用的是 from selenium import webdriver?这有什么不同吗?

#11 楼 @jacky9947 我也想问问有什么不同

miting #13 · 2015年08月03日 Author

#11 楼 @jacky9947 好久以前的代码了,我猜测可能是 appium 继承了 selenium。具体你可以看下对应的代码

万万 [该话题已被删除] 中提及了此贴 11月08日 18:09
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册