新手区 [已解决] Appium 在 Selendroid 模式下,运行报错:Waited 20 secs for selendroid server and it never showed up

shootingstar · 2015年03月30日 · 最后由 gy 回复于 2017年05月23日 · 2166 次阅读

大家好,今天在写自动化的时候,碰到了如下问题,运行 Automator 模式可以正常启动 APP,但是 Selendroid 模式碰到了以下的问题,请大家帮忙看下,谢谢!

环境:
Appium: V1.3.4
Android 版本:5.0.1
Java-client 版本:1.2.1
selenium-java:2.44
selenium-server-standalone:2.44.0

运行步骤:
首先启动 Appium:

D:\Users\full>appium -a 127.0.0.1 -p 4723 -U HC4AAWME0163

info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"udid":"HC4AAWME0163","address":"127.0.0
.1"}
info: Console LogLevel: debug

接着报错 Log 如下:

info: --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"selendr
oid","app":"D:\\workspace\\appiumDemo\\apps\\android\\Ctrip_Wireless_View_V6.3.0
_SIT8.6_TEST.apk","platformVersion":"5.0.1","keystorePath":"D:\\androidKeyStore\
\android.keystore","deviceName":"HC4AAWME0163","platformName":"Android","appActi
vity":".home.CtripSplashActivity ","keyAlias":"ctrip","keystorePassword":"CtripA
ndroid","keyPassword":"CtripAndroid","useKeystore":true,"appPackage":"ctrip.andr
oid.view"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] Using local app from desired caps: D:\workspace\appiumDemo\apps\an
droid\Ctrip_Wireless_View_V6.3.0_SIT8.6_TEST.apk
info: [debug] Creating new appium session 61d4f8f6-b9e1-4ac3-af3e-86a99a48a25c
info: [debug] Starting selendroid server
info: [debug] Getting Java version
info: Java version is: 1.6.0_43
info: [debug] Checking whether selendroid is built yet
info: [debug] Selendroid server exists!
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: [debug] Checking whether adb is present
info: [debug] Using adb from D:\androidsdkwin\platform-tools\adb.exe
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device HC4AAWME0163
info: [debug] Setting device id to HC4AAWME0163
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 wait-for-device
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from D:\androidsdkwin\build-tools\android-4.4.2\aapt.ex
e
info: [debug] Checking if has internet permission from manifest.
info: [debug] executing cmd: D:\androidsdkwin\build-tools\android-4.4.2\aapt.exe
 dump badging D:\workspace\appiumDemo\apps\android\Ctrip_Wireless_View_V6.3.0_SI
T8.6_TEST.apk
info: [debug] Rebuilt selendroid server already exists, no need to rebuild it wi
th a new manifest
info: [debug] Checking signed status of d:\Users\full\AppData\Local\Temp\selendr
oid.ctrip.android.view.apk
info: [debug] Printing keystore md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -list -ali
as ctrip -keystore D:\androidKeyStore\android.keystore -storepass CtripAndroid
info: [debug] Checking signed status of D:\workspace\appiumDemo\apps\android\Ctr
ip_Wireless_View_V6.3.0_SIT8.6_TEST.apk
info: [debug] Printing keystore md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -list -ali
as ctrip -keystore D:\androidKeyStore\android.keystore -storepass CtripAndroid
info: [debug] Keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Entry: META-INF/CTRIP.RSA
info: [debug] entryPath: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t
info: [debug] entryFile: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t\META-INF\CTRIP.RSA
info: [debug] extracted!
info: [debug] Printing apk md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -printcert
 -file d:\Users\full\AppData\Local\Temp\ctrip.android.view\cert\META-INF\CTRIP.R
SA
info: [debug] Keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Entry: META-INF/CTRIP.RSA
info: [debug] entryPath: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t
info: [debug] entryFile: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t\META-INF\CTRIP.RSA
info: [debug] extracted!
info: [debug] Printing apk md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -printcert
 -file d:\Users\full\AppData\Local\Temp\ctrip.android.view\cert\META-INF\CTRIP.R
SA
info: [debug] entryHash MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug]  keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Matches keystore? true
info: [debug] entryHash MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug]  keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Matches keystore? true
info: [debug] Rebuilt selendroid apk exists, doing nothing
info: [debug] Getting install status for ctrip.android.view.selendroid
info: [debug] Getting device API level
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 21
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "pm list packages -3 ctrip.android.view.selendroid"
info: [debug] App is installed
info: [debug] Rebuilt selendroid is already installed
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "getprop persist.sys.language"
info: [debug] Current device persist.sys.language:
info: [debug] java -jar "D:\Users\full\AppData\Roaming\npm\node_modules\appium\n
ode_modules\appium-adb\jars\appium_apk_tools_1.6.jar" "stringsFromApk" "D:\works
pace\appiumDemo\apps\android\Ctrip_Wireless_View_V6.3.0_SIT8.6_TEST.apk" "d:\Use
rs\full\AppData\Local\Temp\ctrip.android.view"
info: [debug] No strings.xml for language '', getting default strings.xml
info: [debug] java -jar "D:\Users\full\AppData\Roaming\npm\node_modules\appium\n
ode_modules\appium-adb\jars\appium_apk_tools_1.6.jar" "stringsFromApk" "D:\works
pace\appiumDemo\apps\android\Ctrip_Wireless_View_V6.3.0_SIT8.6_TEST.apk" "d:\Use
rs\full\AppData\Local\Temp\ctrip.android.view"
warn: Error getting strings.xml from apk
info: [debug] Exception in thread "main" brut.androlib.AndrolibException: Could
not decode arsc file
        at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:54)
        at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:540)
        at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.jav
a:76)
        at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.jav
a:68)
        at io.appium.apktools.StringsXML.run(StringsXML.java:84)
        at io.appium.apktools.Main.main(Main.java:31)
Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000
        at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48)
        at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:43)
        at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:10
0)
        at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:81)
        at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:49)
        ... 5 more

info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Printing keystore md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -list -ali
as ctrip -keystore D:\androidKeyStore\android.keystore -storepass CtripAndroid
info: [debug] Keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Entry: META-INF/CTRIP.RSA
info: [debug] entryPath: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t
info: [debug] entryFile: d:\Users\full\AppData\Local\Temp\ctrip.android.view\cer
t\META-INF\CTRIP.RSA
info: [debug] extracted!
info: [debug] Printing apk md5.
info: [debug] executing cmd: "C:\Java\jdk1.6.0_43\bin\keytool.exe" -v -printcert
 -file d:\Users\full\AppData\Local\Temp\ctrip.android.view\cert\META-INF\CTRIP.R
SA
info: [debug] entryHash MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug]  keystore MD5: C3:B0:58:8D:FC:19:31:58:27:A4:C1:9D:1C:97:62:2C
info: [debug] Matches keystore? true
info: [debug] MD5 for app is 4ff28e65cab7569e573ebf019437cb70
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "ls /data/local/tmp/4ff28e65cab7569e573ebf019437cb70.apk"
info: [debug] Getting install status for ctrip.android.view
info: [debug] Getting device API level
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 21
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "pm list packages -3 ctrip.android.view"
info: [debug] App is installed
info: App is already installed, resetting app
info: [debug] Running fast reset (stop and clear)
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "am force-stop ctrip.android.view"
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "pm clear ctrip.android.view"
info: [debug] Forwarding system:8080 to device:8080
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 forward tcp:8080 tcp:8080
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 install "D:\Users\full\AppData\Roaming\npm\node_modules\appium\build\settin
gs_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 install "D:\Users\full\AppData\Roaming\npm\node_modules\appium\build\unlock
_apk\unlock_apk-debug.apk"
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] executing cmd: D:\androidsdkwin\platform-tools\adb.exe -s HC4AAWME
0163 shell "am instrument -e main_activity 'ctrip.android.view.home.CtripSplashA
ctivity ' ctrip.android.view.selendroid/io.selendroid.ServerInstrumentation"
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hu
b/status","method":"GET"}
info: [debug] 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: [debug] Error: Waited 20 secs for selendroid server and it never showed up

    at D:\Users\full\AppData\Roaming\npm\node_modules\appium\lib\devices\android
\selendroid.js:338:14
    at Request._callback (D:\Users\full\AppData\Roaming\npm\node_modules\appium\
lib\devices\common.js:121:5)
    at self.callback (D:\Users\full\AppData\Roaming\npm\node_modules\appium\node
_modules\request\request.js:121:22)
    at Request.emit (events.js:95:17)
    at ClientRequest.self.clientErrorHandler (D:\Users\full\AppData\Roaming\npm\
node_modules\appium\node_modules\request\request.js:230:10)
    at ClientRequest.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1551:9)
    at Socket.emit (events.js:95:17)
    at net.js:440:14
    at process._tickDomainCallback (node.js:463:13)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: Waited 20 secs for selendro
id server and it never showed up)","origValue":"Waited 20 secs for selendroid se
rver and it never showed up"},"sessionId":null}
info: <-- POST /wd/hub/session 500 30885.535 ms - 240

尝试的解决办法:

  1. 首先在我们的论坛上面搜到了一篇相关的,但是下面没有提到相应的解决办法 2.然后转向到了 Google:在上面确实搜到了一篇 https://github.com/appium/appium/issues/3227,按照上面的说法,尝试如下: a. 删除 java adb shell pm list package selendroid 列出来的所有包 b. 删除用户目录下的/AppData/Local/Temp 里面的 Selendroid* 文件 但是仍然没有解决,请大家帮忙看看,谢谢~

附代码:

import java.io.File;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;

public class test {
    public static void main (String[] args){
        try{
            AppiumDriver driver = null;
            // set up appium
            File classpathRoot = new File(System.getProperty("user.dir"));
            File appDir = new File(classpathRoot, "apps/android");
            File app = new File(appDir, "Ctrip_Wireless_View_V6.3.0_SIT8.6_TEST.apk");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("automationName","selendroid");
            capabilities.setCapability("platformName","Android");
            capabilities.setCapability("deviceName","HC4AAWME0163");  //Android Emulator
            capabilities.setCapability("platformVersion", "5.0.1");
            capabilities.setCapability("app", app.getAbsolutePath());

            capabilities.setCapability("useKeystore", true);
            capabilities.setCapability("keystorePath", "D:\\1234");
            capabilities.setCapability("keystorePassword", "1234");
            capabilities.setCapability("keyAlias", "1234");
            capabilities.setCapability("keyPassword", "1234");

            capabilities.setCapability("appPackage", "ctrip.android.view");  //包名
            capabilities.setCapability("appActivity", ".home.CtripSplashActivity ");   //类名
            driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

            Thread.sleep(20000);

            WebElement myCtrip = driver.findElementById("ctrip.android.view:id/myctrip");
            myCtrip.click();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}

解决方案:
最终用的还是 Appium 的 Selendroid 模式,本地的环境配置如下:
Appium:1.3.4
java-client-2.2.0.jar
selenium-java-2.44.0.jar
selenium-server-standalone-2.44.0.jar
jdk:1.7.0_60
关键问题:一定要详细检查自己的 appPackage 和 appActivity 里面是否有空格

然后按照下面的步骤清理环境:
a. 删除 “adb shell pm list package selendroid” 列出来的所有包
b. 删除用户目录下的/AppData/Local/Temp 里面的 Selendroid* 文件 (Appium 1.3.4 以下的版本,这个文件在 C 盘 Windows 的 Temp 目录下)

上面的 Log 上面有一个:warn: Error getting strings.xml from apk
这个只需要把 Android_home,java_Home,Path 往用户变量里面 Copy 一份即可(环境变量里面设置)

共收到 13 条回复 时间 点赞

你有试过单独用 selendroid 来测吗?
你参考的链接里面的内容貌似已经很旧了(appium 1.2.x 的了)

#1 楼 @chenhengjie123 你好!单独的 selendroid 我倒没有试,我现在升级了一下,下面是我新用到的东西,但还是有同样的问题:
java-client-2.2.0.jar
jdk:1.7.0_60

找到这个:
https://discuss.appium.io/t/error-waited-20-secs-for-selendroid-server-and-it-never-showed-up/722/12
应该不是 appium 的问题,是 selendroid 的问题。改一下 selendroid 版本吧。

@shootingstar@chenhengjie123 我正好也在用 ctrip 的 app 试手,也碰到一样的问题。我用 seledroid 官的 app 可以正常运行,但是 ctrip app 就遇到了和你同样的问题。之前搜到好像因为是 Internet permission 的问题,具体的帖子翻了半天翻不到了。。到底什么问题有待解决~

#4 楼 @woshizh 请问下你用的是 Appium 的 Selendroid 模式,还是单独的 Selendroid?单独的 Selendroid 模式我还没有试,不知道会不会也会有问题,不过看@chenhengjie123提供的帖子貌似是 Selendroid 的问题。
还有一个我比较纳闷的是,我们这边有人用 Appium 的 Selendroid 模式可以成功跑起来我所用的包,唯一不同的地方就是我没有用 maven,所以我想这个问题会不会和我本地的配置有关,或者就是缺少 Jar 包~

@shootingstar 我既有用过 Appium 的 Selendroid 模式,也有用过单独的 Selendroid。发现两个都报错。。

@chenhengjie123 @woshizh 两位好,这个问题我解决了,最终用的还是 Appium 的 Selendroid 模式,现在我本地的环境配置如下:
Appium:1.3.4
java-client-2.2.0.jar
selenium-java-2.44.0.jar
selenium-server-standalone-2.44.0.jar
jdk:1.7.0_60
关键问题:一定要详细检查自己的 appPackage 和 appActivity 里面是否有空格

上面的 Log 上面有一个:warn: Error getting strings.xml from apk
这个只需要把 Android_home,java_Home,Path 往用户变量里面 Copy 一份即可

@shootingstar 学习了,我也试下。。

#7 楼 @shootingstar Activity 里面有空格!?好吧,刚刚再看了一下 log,发现确实有空格:

"appActivity":".home.CtripSplashActivity ",

看样子我还不够仔细。。。学习了。

麻烦把解决方案放到帖子内容中,并把帖子标题改为已解决,方便后面其他遇到相同错误的人。

#9 楼 @chenhengjie123 好的,我也是后来单独运行那条命令的时候才发现这个问题,瞬间感觉石化了都,谢谢你之前的详细解答哈~

为什么我按照楼主的操作但是还是不可以啊...

以下是我的环境配置:
Appium 1.4.0
java-client-1.2.1.jar (可能是因为版本太低吗?)
selenium-java-2.44.0.jar

selenium-server-standalone-2.44.0.jar

1)已经把/local/tmp/selendroid* 文件全部清空(就 1 个)
2)也使用了 adb uninsatll com.xxx.selendroid 清空

可是重新运行 test 还是会报同样的错误,求助。。

解决问题了,居然是因为 activity 名字多写了一些。。。。
话说这种问题怎么能报这种错误呢,感觉充满了误导的恶意。

@seveniruby @woshizh 确定我的 appPackage 和 appActivity 里面没有空格,我也使用了 adb uninsatll com.xxx.selendroid 清空,但是还是提示{"message":"A new session could not be created. (Original error: Waited 20 secs for selendroid server and it never showed up),怎么破?还要一点,我/local/tmp 下咋找不到 selendroid* 呢

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