2017-02-03 42 views
0

如何在安卓記錄按鈕上長按appium測試中的特定時間,由java。 我曾嘗試2種方式,但兩者都根本不工作,這些都是:如何在安卓記錄按鈕(聊天期間)長按appium測試中的特定持續時間,由java

方法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)。

回答

0

它的工作很酷!

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

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

你可以試試這個方法,

TouchAction Action = new TouchAction(driver); 
Action.longPress(driver.findElement(By.name("xyz"))).perform(); 
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(); 
    }