java 脚本内容如下:
public class AppDemo {
private AndroidDriver driver;
@Before
public void setUp() throws Exception {
// set up appium
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "./app");
File app = new File(appDir, "ContactManagerselendroid.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","fa52262d");
capabilities.setCapability("platformVersion", "4.1");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.example.android.contactmanager");
capabilities.setCapability("appActivity", ".ContactManagerselendroid");
capabilities.setCapability("automationName","selendroid");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void addContact(){
WebElement el = driver.findElement(By.name("Add Contact"));
el.click();
List textFieldsList = driver.findElementsByClassName("android.widget.EditText");
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.swipe(10, 10, 10, 10, 1);
driver.findElementByName("Save").click();
}
}
===================appium 的 selendroid 模式下日志内容如下===================================
Starting Node Server
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: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"16","automationName":"Selendroid"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"selendroid","platformVersion":"4.1","app":"E:\workspace\myAppium.\app\ContactManagerselendroid.apk","platformName":"Android","deviceName":"fa52262d","browserName":"","appActivity":".ContactManagerselendroid","appPackage":"com.example.android.contactmanager"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] Using local app from desired caps: E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] Creating new appium session dda5f107-2fe3-481a-94bf-248ad7bf0d22
info: [debug] Starting selendroid server
info: [debug] Getting Java version
info: Java version is: 1.7.0_65
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 F:\android_sdk\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: F:\android_sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device cfcc43fd
info: [debug] Setting device id to cfcc43fd
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd wait-for-device
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from F:\android_sdk\build-tools\21.1.2\aapt.exe
info: [debug] Checking if has internet permission from manifest.
info: [debug] executing cmd: F:\android_sdk\build-tools\21.1.2\aapt.exe dump badging E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] Rebuilt selendroid server already exists, no need to rebuild it with a new manifest
info: [debug] Checking signed status of C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk
info: [debug] Checking app cert for C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk.
info: [debug] executing cmd: java -jar F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\appium-adb\jars\verify.jar C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk
info: [debug] Checking signed status of E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] Checking app cert for E:\workspace\myAppium\app\ContactManagerselendroid.apk.
info: [debug] executing cmd: java -jar F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\appium-adb\jars\verify.jar E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] App already signed.
info: [debug] Zip-aligning E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from F:\android_sdk\build-tools\21.1.2\zipalign.exe
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: F:\android_sdk\build-tools\21.1.2\zipalign.exe -f 4 E:\workspace\myAppium\app\ContactManagerselendroid.apk C:\Users\CHENGH~1\AppData\Local\Temp\appium11506-8028-1b6azw5.tmp
info: [debug] App already signed.
info: [debug] Zip-aligning C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from F:\android_sdk\build-tools\21.1.2\zipalign.exe
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: F:\android_sdk\build-tools\21.1.2\zipalign.exe -f 4 C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk C:\Users\CHENGH~1\AppData\Local\Temp\appium11506-8028-1p39k07.tmp
info: [debug] Rebuilt selendroid apk does not exist, uninstalling any instances of it on device to make way for new one
info: [debug] Uninstalling com.example.android.contactmanager.selendroid
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "am force-stop com.example.android.contactmanager.selendroid"
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd uninstall com.example.android.contactmanager.selendroid
info: [debug] App was uninstalled
info: [debug] Getting install status for com.example.android.contactmanager.selendroid
info: [debug] Getting device API level
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 16
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "pm list packages -3 com.example.android.contactmanager.selendroid"
info: [debug] App is not installed
info: [debug] Rebuilt selendroid is not installed, installing it
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd install -r "C:\Users\CHENGH~1\AppData\Local\Temp\selendroid.com.example.android.contactmanager.apk"
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "getprop persist.sys.language"
info: [debug] Current device persist.sys.language: zh
info: [debug] java -jar "F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "E:\workspace\myAppium\app\ContactManagerselendroid.apk" "C:\Users\CHENGH~1\AppData\Local\Temp\com.example.android.contactmanager" zh
info: [debug] No strings.xml for language 'zh', getting default strings.xml
info: [debug] java -jar "F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "E:\workspace\myAppium\app\ContactManagerselendroid.apk" "C:\Users\CHENGH~1\AppData\Local\Temp\com.example.android.contactmanager"
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Checking app cert for E:\workspace\myAppium\app\ContactManagerselendroid.apk.
info: [debug] executing cmd: java -jar F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\appium-adb\jars\verify.jar E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] App already signed.
info: [debug] Zip-aligning E:\workspace\myAppium\app\ContactManagerselendroid.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from F:\android_sdk\build-tools\21.1.2\zipalign.exe
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: F:\android_sdk\build-tools\21.1.2\zipalign.exe -f 4 E:\workspace\myAppium\app\ContactManagerselendroid.apk C:\Users\CHENGH~1\AppData\Local\Temp\appium11506-8028-14u0p7p.tmp
info: [debug] MD5 for app is 6d2ffe9de6e0da4dac74094e843664ce
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "ls /data/local/tmp/6d2ffe9de6e0da4dac74094e843664ce.apk"
info: [debug] Getting install status for com.example.android.contactmanager
info: [debug] Getting device API level
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 16
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "pm list packages -3 com.example.android.contactmanager"
info: [debug] App is installed
info: App is already installed, resetting app
info: [debug] Running fast reset (stop and clear)
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "am force-stop com.example.android.contactmanager"
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "pm clear com.example.android.contactmanager"
info: [debug] Forwarding system:8080 to device:8080
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd forward tcp:8080 tcp:8080
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd install "F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd install "F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] executing cmd: F:\android_sdk\platform-tools\adb.exe -s cfcc43fd shell "am instrument -e main_activity 'com.example.android.contactmanager.ContactManagerselendroid' com.example.android.contactmanager.selendroid/io.selendroid.ServerInstrumentation"
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/status,method:GET"}
info: [debug] Cleaning up appium session
info: [debug] Error: Waited 20 secs for selendroid server and it never showed up
at F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\lib\devices\android\selendroid.js:338:14
at Request._callback (F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\lib\devices\common.js:121:5)
at self.callback (F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\request\request.js:121:22)
at Request.EventEmitter.emit (events.js:95:17)
at ClientRequest.self.clientErrorHandler (F:\appium\AppiumForWindows-1.3.4.1\node_modules\appium\node_modules\request\request.js:230: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._tickDomainCallback (node.js:459: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 selendroid server and it never showed up)","origValue":"Waited 20 secs for selendroid server and it never showed up"},"sessionId":null}
info: <-- POST /wd/hub/session 500 38701.063 ms - 240
error: Failed to start an Appium session, err was: Error: Waited 20 secs for selendroid server and it never showed up
请知道的朋友告诉我一下原因,谢谢