Appium appium 运行示例 android_contact.py 报错

mongnet · 2014年04月16日 · 最后由 mongnet 回复于 2014年04月17日 · 1941 次阅读

步骤是按
新手贴:Windows 平台上的使用 Python 语言实现 appium 自动化程序 for Android(完整版)http://testerhome.com/topics/646
这里操作的,我是直接到连接的真机,试了二台电脑,都提示这种错误,各位大牛来指教一下

android_contact.py 脚本

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'] = 'Selendroid' #Selendroid Android
desired_caps['browserName'] = ''
desired_caps['version'] = '4.1.2'
desired_caps['app'] = PATH('E:\pythonDemo\ContactManager.apk')
desired_caps['app-package'] = 'com.example.android.contactmanager'
desired_caps['app-activity'] = '.ContactManager'

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

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()

appium 报错如下

info: Zip-aligning E:\pythonDemo\ContactManager.apk
info: Checking whether zipalign is present
info: [ADB] Using zipalign from D:\AndroidSDK\sdk\tools\zipalign.exe
debug: zipAlignApk: "D:\AndroidSDK\sdk\tools\zipalign.exe" -f 4 "E:\pythonDemo\ContactMana
ger.apk" "C:\Users\myhu\AppData\Local\Temp\appium114316-8764-uqq9fb.tmp"
error: uncaughtException: EXDEV, cross-device link not permitted 'C:\Users\myhu\AppData\Lo
cal\Temp\appium114316-8764-uqq9fb.tmp' date=Wed Apr 16 2014 21:51:35 GMT+0800 (中国标准时
), pid=8764, uid=null, gid=null, cwd=C:\Users\myhu\AppData\Roaming\npm\node_modules\appi
um, execPath=D:\Program Files\nodejs\node.exe, version=v0.10.26, argv=[node, C:\Users\myhu
\AppData\Roaming\npm\node_modules\appium\bin\appium.js], rss=53436416, heapTotal=51602664,
 heapUsed=26173080, loadavg=[0, 0, 0], uptime=2357.6278332, trace=[column=18, file=fs.js,
function=Object.fs.renameSync, line=543, method=fs.renameSync, native=false, column=10, fi
le=C:\Users\myhu\AppData\Roaming\npm\node_modules\appium\lib\devices\android\adb.js, funct
ion=null, line=465, method=null, native=false, column=7, file=child_process.js, function=C
hildProcess.exithandler, line=635, method=exithandler, native=false, column=17, file=event
s.js, function=ChildProcess.EventEmitter.emit, line=98, method=EventEmitter.emit, native=f
alse, column=16, file=child_process.js, function=maybeClose, line=743, method=null, native
=false, column=5, file=child_process.js, function=Process.ChildProcess._handle.onexit, lin
e=810, method=ChildProcess._handle.onexit, native=false], stack=[Error: EXDEV, cross-devic
e link not permitted 'C:\Users\myhu\AppData\Local\Temp\appium114316-8764-uqq9fb.tmp',
at Object.fs.renameSync (fs.js:543:18),     at C:\Users\myhu\AppData\Roaming\npm\node_modu
les\appium\lib\devices\android\adb.js:465:10,     at ChildProcess.exithandler (child_proce
ss.js:635:7),     at ChildProcess.EventEmitter.emit (events.js:98:17),     at maybeClose (
child_process.js:743:16),     at Process.ChildProcess._handle.onexit (child_process.js:810
:5)]

python android_contact.py 报错如下:

E:\pythonDemo>python android_contact.py
Traceback (most recent call last):
  File "android_contact.py", line 17, in <module>
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 71, in
 __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 113, i
n start_session
    'desiredCapabilities': desired_capabilities,
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 162, i
n execute
    response = self.command_executor.execute(driver_command, params)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", lin
e 349, in execute
    return self._request(command_info[0], url, body=data)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", lin
e 417, in _request
    resp = opener.open(request)
  File "D:\Python27\lib\urllib2.py", line 404, in open
    response = self._open(req, data)
  File "D:\Python27\lib\urllib2.py", line 422, in _open
    '_open', req)
  File "D:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "D:\Python27\lib\urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "D:\Python27\lib\urllib2.py", line 1187, in do_open
    r = h.getresponse(buffering=True)
  File "D:\Python27\lib\httplib.py", line 1045, in getresponse
    response.begin()
  File "D:\Python27\lib\httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "D:\Python27\lib\httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "D:\Python27\lib\socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 10054]
共收到 8 条回复 时间 点赞

这种帖子我喜欢,代码就是代码 ,不贴图,先赞,再看。

#1 楼 @lihuazhang log 略蛋疼。。。

谢谢 @monkey @lihuazhang 光临

monkey 蛋疼的地方还情况明示_^

把你的 apk 放到 D 盘去再试试看。

#4 楼 @lihuazhang 我在公司里是在同一个目录也会出这个问题,是不是要同 node.js 同一个目录才行? 我 node.js 安装在 C 盘的

#4 楼 @lihuazhang 我把 APK 放到 C 盘就没有出现这个错误了,可以正常安装和打开应用,但又出现了新的错误,打开应用后就停在那里不动了
我看这里怎么变成 8080 端口了?

info: Found an apk we want to keep at /data/local/tmp/b2d2916bb5388e1dc281ec3e71
ef1234.apk
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 shell r
m "/data/local/tmp/mq_1385110084.apk" && rm "/data/local/tmp/mq_1387864898.apk"
&& rm "/data/local/tmp/mq_1387865010.apk" && rm "/data/local/tmp/mq_1389000903.a
pk" && rm "/data/local/tmp/mq_1397224934.apk"
warn:  killed=false, code=1, signal=null
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 shell "
pm install -r /data/local/tmp/b2d2916bb5388e1dc281ec3e71ef1234.apk"
info: [ADB] Forwarding system:8080 to device:8080
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 forward
 tcp:8080 tcp:8080
debug: Pushing unlock helper app to device...
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 install
 "C:\Users\hubiao\AppData\Roaming\npm\node_modules\appium\build\unlock_apk\unloc
k_apk-debug.apk"
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 shell "
dumpsys window"
info: Writing dumpsys output to C:\Users\hubiao\AppData\Roaming\npm\node_modules
\appium\.dumpsys.log
debug: Screen already unlocked, continuing.
debug: executing: "E:\AndroidSdk\sdk\platform-tools\adb.exe" -s 5dd37976 shell "
am instrument -e main_activity 'com.example.android.contactmanager.ContactManage
r' com.example.android.contactmanager.selendroid/io.selendroid.ServerInstrumenta
tion"
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/status
","method":"GET"}
info: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Waited 20 secs for sel
endroid server and it never showed up
info: Error: Waited 20 secs for selendroid server and it never showed up
    at C:\Users\hubiao\AppData\Roaming\npm\node_modules\appium\lib\devices\andro
id\selendroid.js:258:14
    at Request._callback (C:\Users\hubiao\AppData\Roaming\npm\node_modules\appiu
m\lib\devices\common.js:103:5)
    at self.callback (C:\Users\hubiao\AppData\Roaming\npm\node_modules\appium\no
de_modules\request\request.js:129:22)
    at Request.EventEmitter.emit (events.js:95:17)
    at ClientRequest.self.clientErrorHandler (C:\Users\hubiao\AppData\Roaming\np
m\node_modules\appium\node_modules\request\request.js:239:10)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1547:9)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:415:13)
info: Responding to client with error: {"status":33,"value":{"message":"A new se
ssion could not be created. (Original error: Waited 20 secs for selendroid serve
r and it never showed up)","origValue":"Waited 20 secs for selendroid server and
 it never showed up"},"sessionId":null}
POST /wd/hub/session 500 43722ms - 268b

试了下用模拟器模拟 4.4.2

desired_caps['device'] = 'Android' #Selendroid 
desired_caps['version'] = '4.4.2'

成功执行所有操作

但如果

desired_caps['device'] = 'Selendroid' 

设置成 Selendroid 还是会有 8080 的问题,出现一样的错误,是在这个模式下要设置些什么东西?

#7 楼 @mongnet 请问楼主,我也是 desired_caps['device'] = 'Selendroid' 时会出现 WebDriverException: Message: u'A new session could not be created. (Original error: hasInternetPermissionFromManifest failed. Error: Command failed: /bin/sh -c "/opt/adt-sdk/sdk/build-tools/android-4.4W/aapt" dump badging \nERROR: no dump file specified\n)'
请问这是什么原因?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册