Appium Appium 程序报错 A new session could not be created

落叶秋心 · 2017年02月16日 · 最后由 落叶秋心 回复于 2017年02月20日 · 2218 次阅读

第一个 appium 程序,安装一个慕课网 app 到模拟器,但一直报错,已经折磨了好几天了,麻烦各位大神帮忙解决一下

先讲一下版本:
window7 64 位
Appium:1.4.16
node:v6.9.4
jdk:1.8.0_111

模拟器已经启动,appium server 也启动,运行程序报错如下:
eclipse Java 代码

package com.imooc.test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;

public class AppTest {
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        AndroidDriver driver;
        DesiredCapabilities cap=new DesiredCapabilities();

        cap.setCapability("deviceName","emulator-5554");//设备名
        cap.setCapability("platformVersion", "7.0");//平台版本
        cap.setCapability("automationName", "Appium");//使用测试的引擎
        cap.setCapability("platformName", "Android");//平台名
        cap.setCapability("app", "D:\\Testing\\mukewang.apk");//app 绝对地址
        cap.setCapability("appPackage", "cn.com.open.mooc");//app 的包名
        cap.setCapability("appActivity", "cn.com.open.mooc.index.splash.MCSplashActivity");
        cap.setCapability("devicereadyTimeout", 30);
        cap.setCapability("unicodeKeyboard", true);
        cap.setCapability("resetKeyboard", true);

        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        Thread.sleep(5000);
        driver.quit();
    }
}

eclipse 报错显示

二月 16, 2017 4:00:29 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: D:\Testing\Android\android-sdk_r23.0.2-windows\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 install "D:\Testing\AppiumForWindows_1_4_16_1\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk"
Failed to install D:\Testing\AppiumForWindows_1_4_16_1\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.android.ime without first uninstalling.]
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'PC201403181853', ip: '113.251.221.110', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:161)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
    at com.imooc.test.AppTest.main(AppTest.java:29)

appium 的 log 报错显示如下,这里截取关键部分,太长了

C:\Users\Administrator>appium
(node:7496) fs: re-evaluating native module sources is not supported. If you a
 using the graceful-fs module, please update it to a more recent version.
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug

info: Client User-Agent string: Apache-HttpClient/4.5.2 (Java/1.8.0_111)
info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : devicereadyTimeout
info: [debug] Using local app from desired caps: D:\Testing\mukewang.apk
info: [debug] Creating new appium session 6b9cd909-b031-4012-9260-df77976a2199

warn: UiAutomator did not shut down fast enough, calling it gone
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Command failed: D:\Tes
ting\Android\android-sdk_r23.0.2-windows\android-sdk-windows\platform-tools\adb.
exe -s emulator-5554 install "D:\Testing\AppiumForWindows_1_4_16_1\Appium\node_m
odules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk"
Failed to install D:\Testing\AppiumForWindows_1_4_16_1\Appium\node_modules\appiu
m\build\unicode_ime_apk\UnicodeIME-debug.apk: Failure [INSTALL_FAILED_ALREADY_EX
ISTS: Attempt to re-install io.appium.android.ime without first uninstalling.]

info: [debug] Error: Command failed: D:\Testing\Android\android-sdk_r23.0.2-wind
ows\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 install "D:\Test
ing\AppiumForWindows_1_4_16_1\Appium\node_modules\appium\build\unicode_ime_apk\U
nicodeIME-debug.apk"
Failed to install D:\Testing\AppiumForWindows_1_4_16_1\Appium\node_modules\appiu
m\build\unicode_ime_apk\UnicodeIME-debug.apk: Failure [INSTALL_FAILED_ALREADY_EX
ISTS: Attempt to re-install io.appium.android.ime without first uninstalling.]

最后,如果能有人回答,真的无比感谢!谢谢!

共收到 4 条回复 时间 点赞

看看这个:
Starting Appium fails on Android N (Nougat)

试下在模拟器上能装上输入法吗?

adb uninstall io.appium.android.ime
adb install D:\Test
ing\AppiumForWindows_1_4_16_1\Appium\node_modules\appium\build\unicode_ime_apk\U
nicodeIME-debug.apk

感谢!
我的程序在模拟器上安装成功,但 eclipse 还是报错
eclipse 报错如下

二月 16, 2017 7:55:27 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end

appium log 显示如下

info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : devicereadyTimeout
info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : devicereadyTimeout

你把这个日志翻译成中文看看?已经说得很明白了。

好的,谢谢!

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