如何通过java在appium测试中长时间按下Android记录按钮(在聊天期间)特定的持续时间

时间:2017-02-03 13:32:41

标签: java android appium

如何通过java在appium测试中长按特定时间的Android记录按钮。 我尝试了两种方法,但两种方法都没有用,那些方法是:

方式1:

By pressRecBtn = By.id("recorderButton");
int x = 353;  // x coordinate of device screen, get it after enabling the Show touch and Pointer location from developer option 
int y = 980; // same as x
int timeInMs = 4000;

Action.longPress(driver.findElement(pressRecBtn)).longPress(x, y, timeInMs).perform();

方式2:

By pressRecBtn = By.id("recorderButton");
int timeInMs = 4000;

Action.longPress(driver.findElement(pressRecBtn)).waitAction(timeInMs).perform();

以这种方式按下rec按钮但是默认时间(> = 1000 MS)。

3 个答案:

答案 0 :(得分:0)

你可以这样试试,

 TouchAction Action = new TouchAction(driver);
 Action.longPress(driver.findElement(By.name("xyz"))).perform();

答案 1 :(得分:0)

它的工作很酷!!

By tapOnRecIcon = By.id("btnRecord");    
int timeInMs = 4000;
TouchAction touchAction = new TouchAction((MobileDriver) driver);

touchAction.longPress(driver.findElement(pressRecBtn),timeInMs).release().perform();

答案 2 :(得分:0)

public void longClick(String element) {
        // TODO Auto-generated method stub
        WebElement webElement = appiumDriver.findElement(By.xpath(element));

        TouchAction Action = new TouchAction(appiumDriver);
        Action.longPress(webElement).release().perform();
    }