我是移动设备(Android)中的自动化测试(Selenium Grid和appium)的新手,我在物理安卓设备(三星Galaxy S5)中遇到了longPress操作的问题。当我调用longPress(WebElement el,int x,int y)时,似乎appium不尊重我作为参数给出的坐标并且保持长按在TextView元素的中心。在Appium日志中,我看到它获取了我的坐标但是当它执行longPress操作时它位于元素的中心。
以下是来自appium实例的日志:
info: --> POST /wd/hub/session/8db9e619-aabb-4a55-81a8-f7a35e342b4c/touch/perform {"actions":[{"action":"longPress","options":{"element":"15","x":100,"y":0}}]}
info: [debug] Pushing command to appium work queue: ["element:getLocation",{"elementId":"15"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getLocation","params":{"elementId":"15"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getLocation
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"x":102,"y":527}}
info: [debug] Pushing command to appium work queue: ["element:getSize",{"elementId":"15"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getSize","params":{"elementId":"15"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getSize
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"width":876,"height":124}}
info: [debug] Pushing command to appium work queue: ["element:touchLongClick",{"elementId":"15","x":202,"y":527,"duration":1000}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchLongClick","params":{"elementId":"15","x":202,"y":527,"duration":1000}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: touchLongClick
info: [debug] [BOOTSTRAP] [debug] Performing TouchLongClick using element? true x: 540, y: 589, duration: 1000
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"}},"sessionId":"8db9e619-aabb-4a55-81a8-f7a35e342b4c"}
info: <-- GET /wd/hub/status 200 0.698 ms - 156 {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"}},"sessionId":"8db9e619-aabb-4a55-81a8-f7a35e342b4c"}
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
Appium version: 1.4.13.1
java-client-3.2.0
有什么想法吗?似乎没有其他人遇到过这个问题,因为我在谷歌搜索中找不到任何相关内容。谢谢!
编辑: 代码如下
public void act_enterSubscriberClearedInput(String subscriber) {
appiumcontroller().tap(subscriberUIElement);
appiumcontroller().longPress(subscriberUIElement, 100, 0);
appiumcontroller().sendAndroidKeyEvent(AndroidKeyEvent.DEL);
appiumcontroller().sendKeys(subscriberUIElement, subscriber);
appiumcontroller().tap(BTN_OK);
}
public MobileController longPress(String locator, int x, int y) {
this.performTouchAction(getTouchAction().longPress(waitForMobileElement(Constants.VISIBILITY.get(), locator, appiumDriver),x,y));
return this;
}