大家好,今天在写自动化的时候,碰到了如下问题,运行 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
尝试的解决办法:
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 一份即可(环境变量里面设置)