2

我是移动设备(android)中自动化测试(Selenium Grid 和 appium)的新手,我在物理 android 设备(Samsung 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;
    }
4

0 回答 0