环境
使用 win7 64 位(使用 win7 32 位也提示同样错误)
java 版本是 1.8 的版本(试过 1.7 的版本同样报错)
java 的环境变量我也已经排查过没问题
appium 在线安装和安装.exe 安装都同样报错
试过其他 python 编译器运行也报错
备注:
如果仍有格式问题,我下班后回家在做修改,请勿删帖感谢,这个问题我跟着 7,8 天了百度搜的方法贴边的都试了还是搞不定,有谁遇到同样的问题解决了跪求请分享一下经验!(我用 Markdown Pad2 编译的时候排版不错,怎么贴上了就成这熊样了)
appium 报错如下:
info: Client User-Agent string: Python-urllib/2.7 error: Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT info: [debug] Using local app from desired caps: C:\ContactManager.apk info: [debug] Creating new appium session 0acb2738-8bce-4fd7-b4b0-ce4d93c09411 info: Starting android appium info: [debug] Getting Java version info: [debug] Cleaning up android objects info: [debug] Cleaning up appium session info: [debug] Error: 'java -version' failed. Error: spawn ENOENT at [object Object]. (C:\Program Files (x86)\Appium\nodemodules\appium\lib\devices\android\android-common.js:1057:17) at exithandler (childprocess.js:633:7) at ChildProcess.errorhandler (childprocess.js:649:5) at ChildProcess.EventEmitter.emit (events.js:95:17) at Process.ChildProcess.handle.onexit (childprocess.js:795:12) info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null} info: <-- POST /wd/hub/session 500 15.011 ms - 208 info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"NX507J","app":"C:\ContactManager.apk","platformVersion":"4.4.2","appPackage":"com.example.android.contactmanager","platformName":"Android","appActivity":".ContactManager"}} info: Client User-Agent string: Python-urllib/2.7 error: Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT info: [debug] Using local app from desired caps: C:\ContactManager.apk info: [debug] Creating new appium session 17ec9dac-c420-4b28-a876-56b5c87f0774 info: Starting android appium info: [debug] Getting Java version info: [debug] Cleaning up android objects info: [debug] Cleaning up appium session info: [debug] Error: 'java -version' failed. Error: spawn ENOENT at [object Object]. (C:\Program Files (x86)\Appium\nodemodules\appium\lib\devices\android\android-common.js:1057:17) at exithandler (childprocess.js:633:7) at ChildProcess.errorhandler (childprocess.js:649:5) at ChildProcess.EventEmitter.emit (events.js:95:17) at Process.ChildProcess.handle.onexit (childprocess.js:795:12) info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null} info: <-- POST /wd/hub/session 500 4.283 ms - 20
Python 脚本如下:
import os
import unittest
from appium import webdriver
from time import sleep
PATH = lambda p: os.path.abspath( os.path.join(os.path.dirname(file), p) )
class ContactsAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'NX507J'
desired_caps['app'] = PATH(
'C:/ContactManager.apk'
)
desired_caps['appPackage'] = 'com.example.android.contactmanager'
desired_caps['appActivity'] = '.ContactManager'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
self.driver.quit()
def testaddcontacts(self): el = self.driver.findelementbyaccessibilityid("Add Contact")
el.click()
textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
textfields[0].send_keys("Appium User")
textfields[2].send_keys("someone@appium.io")
self.assertEqual('Appium User', textfields[0].text)
self.assertEqual('someone@appium.io', textfields[2].text)
self.driver.find_element_by_accessibility_id("Save").click()
alert = self.driver.switch_to_alert()
self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click()
self.driver.press_keycode(3)
if name == 'main':
suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
备注
之前有评论让我运行一个他评论写的脚本结果如下:
D:>node D:\test.js
current platform: win32
execute cmd: java -version stdout: C:\ProgramData\Oracle\Java\javapath;D:\androidbag\androidsdk\adt-bundle -windows-x86-20130917\sdk\platform-tools;D:\androidbag\androidsdk\adt-bundle-wi ndows-x86-20130917\sdk\tools;C:\Program Files\TortoiseSVN\bin;C:\Python27;C:\Pyt hon27\Scripts;C:\Users\Administrator\AppData\Roaming\npm\;E:\eclipse\plugins;E:\ java\apache-maven-3.3.3\bin;C:\Program Files (x86)\Appium\node_modules.bin;C:\P rogram Files\nodejs\;C:\Python27\Scripts;D:\jdk\bin;D:\jdk\jre\bin;C:\Users\jins onghao\AppData\Roaming\npm
stderr:
execute cmd: java -version stdout: stderr: java version "1.8.045" Java(TM) SE Runtime Environment (build 1.8.045-b15) Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)