【问题标题】:appium automation using java使用java实现appium自动化
【发布时间】:2016-10-29 19:40:04
【问题描述】:

我尝试使用 selenium webdriver 自动化一个 android 本机应用程序。请参阅下面的代码。

package appium.eclipse;

import org.testng.annotations.Test;

import java.io.IOException;
import java.net.URL;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;

public class NewTest {
    AppiumDriver<WebElement> dr;

    @BeforeClass
    public void setup() throws IOException{
        DesiredCapabilities first = new DesiredCapabilities();
        first.setCapability(MobileCapabilityType.DEVICE_NAME, "donatello");
        first.setCapability(MobileCapabilityType.APP_ACTIVITY,"com.myapplication.MainActivity");
        first.setCapability(MobileCapabilityType.APP_PACKAGE,"com.myapplicationdev");
        dr=new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),first);
    }

    @Test
    public void launchapp() throws Throwable {
        Thread.sleep(9000);
        //insert pin
        for (int i =0; i<5; i ++) {
            dr.findElementByXPath("//android.view.View[@content-desc='1']").click();
            System.out.println("I clicked" + i );
            Thread.sleep(1000);
        }
        //click login
        Thread.sleep(4000);
        dr.findElementByXPath("//android.view.View[@index='2']").click();
        System.out.println("I clicked Login");
        Thread.sleep(9000);
    }
}

然而,Appium 点击了五次 pin,但没有点击循环外的登录按钮。 Appium 将成功返回给我用于测试的 java 客户端 (eclipse)。

请问我做错了什么。我将非常感谢您提供的任何帮助。

@Manidroid,请看下面的appium日志

> Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 19 --automation-name Appium --device-name "donatello" --log-no-color
> warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
> info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
> 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,"deviceName":"donatello","platformName":"Android","platformVersion":"19","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"appActivity":"com.myapplicationdev.MainActivity","appPackage":"com.myapplication","platformName":"Android","deviceName":"donatello"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_101)
> info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
> info: [debug] Creating new appium session 60ee80cd-ab62-4dcd-8e18-aac9de15aed6
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_101
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe
> warn: No app capability, can't parse package/activity
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" devices
> info: [debug] 1 device(s) connected
> info: Found device 169.254.160.177:5555
> info: [debug] Setting device id to 169.254.160.177:5555
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 wait-for-device
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 19
> info: Device API level is: 19
> info: [debug] Extracting strings for language: default
> info: [debug] Apk doesn't exist locally
> info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "rm -rf /data/local/tmp/strings.json"
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Skipping install since we launched with a package instead of an app path
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe -s 169.254.160.177:5555 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.myapplicationdev -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Waking up device if it's not alive
> info: [debug] Pushing command to appium work queue: ["wake",{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: wake
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "dumpsys window"
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Screen already unlocked, continuing.
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] dataDir set to: /data
> info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"\/data","status":0}
> info: [debug] Getting device API level
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "getprop ro.build.version.sdk"
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
> info: [debug] Device is at API Level 19
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.myapplicationdev/com.myapplicationdev.MainActivity"
> info: [debug] Waiting for pkg "com.myapplicationdev" and activity "com.myapplicationdev.MainActivity" to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "dumpsys window windows"
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "getprop ro.build.version.release"
> info: [debug] Device is at release version 4.4.4
> info: [debug] Device launched! Ready for commands
> info: [debug] Setting command timeout to the default of 60 secs
> info: [debug] Appium session started with sessionId 60ee80cd-ab62-4dcd-8e18-aac9de15aed6
> info: <-- POST /wd/hub/session 303 12203.233 ms - 74 
> info: --> GET /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6 {}
> info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"com.myapplicationdev.MainActivity","appPackage":"com.myapplication","platformName":"Android","deviceName":"donatello"},"appActivity":"com.myapplicationdev.MainActivity","appPackage":"com.myapplication","platformName":"Android","deviceName":"169.254.160.177:5555"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- GET /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6 200 7.357 ms - 644 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"com.myapplicationdev.MainActivity","appPackage":"com.myapplication","platformName":"Android","deviceName":"donatello"},"appActivity":"com.myapplicationdev.MainActivity","appPackage":"com.myapplication","platformName":"Android","deviceName":"169.254.160.177:5555"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@content-desc='1']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@content-desc='1'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=4]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"1"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 512.676 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/1/click {"id":"1"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"1"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/1/click 200 545.815 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@content-desc='1']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@content-desc='1'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=5]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"2"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 312.892 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/2/click {"id":"2"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"2"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/2/click 200 635.001 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@content-desc='1']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@content-desc='1'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=5]
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"3"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 693.547 ms - 87 {"status":0,"value":{"ELEMENT":"3"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"3"},"status":0}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/3/click {"id":"3"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"3"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/3/click 200 457.090 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@content-desc='1']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@content-desc='1'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=6]
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"4"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 233.350 ms - 87 {"status":0,"value":{"ELEMENT":"4"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"4"},"status":0}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/4/click {"id":"4"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"4"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/4/click 200 437.992 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@content-desc='1']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@content-desc='1']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@content-desc='1'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=7]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"5"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"5"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 371.092 ms - 87 {"status":0,"value":{"ELEMENT":"5"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/5/click {"id":"5"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"5"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/5/click 200 231.014 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element {"using":"xpath","value":"//android.view.View[@index='2']"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[@index='2']","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[@index='2']","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[@index='2'] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=3]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"6"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"6"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element 200 170.945 ms - 87 {"status":0,"value":{"ELEMENT":"6"},"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: --> POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/6/click {"id":"6"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"6"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"6"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: <-- POST /wd/hub/session/60ee80cd-ab62-4dcd-8e18-aac9de15aed6/element/6/click 200 326.695 ms - 76 {"status":0,"value":true,"sessionId":"60ee80cd-ab62-4dcd-8e18-aac9de15aed6"}
> info: [debug] Didn't get a new command in 60 secs, shutting down...
> info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: "C:\Users\Eagle\Desktop\Appium\Installations and Configuration\android-sdk-windows\platform-tools\adb.exe" -s 169.254.160.177:5555 shell "input keyevent 3"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 87.663
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] UiAutomator shut down normally
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] We shut down because no new commands came in

【问题讨论】:

  • 我最好的猜测是 XPath 表达式确实匹配其他被点击而不是登录按钮的东西。
  • 谢谢罗伯特,我真的不认为问题出在 xpath 上。这是因为当我将登录名移到代码的第一行时,它被点击了,我得到了一个弹出窗口,要求我先输入 5 位密码。
  • 为了给出正确的解决方案,我们需要遵循这个,1.完整的 Appium 日志 2. UIautomator screenshot
  • 请看下面的appium日志

标签: java android eclipse selenium


【解决方案1】:

能否尝试点击元素的坐标,看看是否有效?

试试这样的 -

Point point = element.getLocation();
int x = point.x;
int y = point.y;

TouchAction touchAction = new TouchAction(driverMobile);
touchAction.tap(x, y).perform();

【讨论】:

  • 感谢 Anish,使用 TouchAction 有效。我观察到,当我从点打印坐标时,我得到了 (179, 424),所以它没有点击按钮。但是当我使用 ui automator 手动获取坐标时,我可以点击它。
  • 您好 Ayoaudu,您在这两种情况下使用的坐标是否相同。通常我会尝试在坐标上添加 5 或 10px 的偏移量,以便它可以在原始坐标是角的情况下工作。所以我一般使用的代码是-touchAction.tap(x+10, y+10).perform();
  • 你好 Anish,我最终使用的坐标与我从点得到的不同。 Point 给了我 (179,424),但我使用了从 uiautomator 获得的 (504, 409)。我实际上担心如果我使用另一个更大或更小的设备,代码将无法工作。
  • ,我现在刚刚尝试了一些东西,我尝试使用下面的代码在我的代码执行开始时获取元素坐标。 WebElement D =dr.findElementByXPath("//android.view.View[@index='2']");点 pt = D.getLocation(); System.out.println(pt); (824,452) 执行一些代码后,我再次使用下面的代码获得了坐标,我意识到它们是不同的。这令人困惑。 WebElement E=dr.findElementByXPath("//android.view.View[@index='2']");点点 = E.getLocation(); System.out.println(point); (179, 424) 造成这种情况的原因是什么?
  • 当您执行一些其他代码时,屏幕中是否发生了任何变化(滚动、显示其他一些元素等)。一个可能的原因可能是在第二次期间,索引 = 2 处的元素可能是其他元素。你能检查一下这两次代码是否引用了同一个对象吗?
猜你喜欢
  • 2014-09-03
  • 2015-04-09
  • 2017-12-30
  • 1970-01-01
  • 2016-02-29
  • 2019-05-29
  • 2013-10-04
  • 2017-02-05
  • 2017-02-24
相关资源
最近更新 更多