简体   繁体   中英

How to long press on android record button(during chat) for a particular time duration in appium test, by java

How to long press on android record button for a particular time in appium test, by java. I have tried 2 ways but both are not working at all, those are:

Way 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();

Way 2:

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

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

for this way its press on rec button but for a default time(>=1000 MS).

You can try this way,

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

Its working cool!!

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

touchAction.longPress(driver.findElement(pressRecBtn),timeInMs).release().perform();
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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM