1、左滑
/**
* ThisMethod for swipe Left
*@paramduring滑動(dòng)速度等待多少毫秒
*/
protected voidswipeLeft(intduring) {
int width =driver.manage().window().getSize().width;
int height =driver.manage().window().getSize().height;
driver.swipe(width*3/4,height /2,width /4,height /2,during);
}
2础拨、向上滑動(dòng)
/**
*?This?Method?for?swipe?up
*?@param?during滑動(dòng)速度等待多少毫秒
*/
protected?void?swipeUp(int?during)?{
int?width?=?driver.manage().window().getSize().width;
int?height?=?driver.manage().window().getSize().height;
driver.swipe(width?/?2,?height?*?3?/?4,?width?/?2,?height?/?4,?during);}
3性锭、向下滑動(dòng)
/**
*?This?Method?for?swipe?down
*?@param?during滑動(dòng)速度等待多少毫秒*/
protected?void?swipeDown(int?during)?{
int?width?=?driver.manage().window().getSize().width;
int?height?=?driver.manage().window().getSize().height;
driver.swipe(width?/?2,?height?/?4,?width?/?2,?height?*?3?/?4,?during);
//?wait?for?page?loading
}
4甥雕、等待page加載元素
/**
*等待Page加載某個(gè)元素
*@paramwebElement頁(yè)面元素
*@paramtimeOutInSeconds最大等待時(shí)間,秒值
*@returnWebElement
*/
protectedWebElementwait(WebElement?webElement,?inttimeOutInSeconds)?{
newWebDriverWait(driver,timeOutInSeconds,100).until(newExpectedCondition()?{
@Nullable
@Override
publicWebElementapply(@NullableWebDriver?driver)?{
if(isExist(webElement))?{
return webElement;
}else{
return?null;}}});
return webElement;
}
5曼振、判斷page元素是否存在
/**
*判斷Page元素是否存在
*@paramwebElementPage元素
*@returnboolean
*/
protected?booleanisExist(WebElement?webElement)?{
if(null==?webElement)?{
return?false;
}try{
webElement.isDisplayed();
return?true;
}catch(NoSuchElementException?e)?{
return?false;
}}
6珍坊、判斷page元素是否存在(加入等待時(shí)間)
*判斷Page元素是否存在
*@paramwebElementPage元素
*@paramtimeOutInSeconds超時(shí)時(shí)間
*@returnboolean
*/
protected?booleanisExist(WebElement?webElement,?inttimeOutInSeconds)?{
if(null==?webElement)?{
return?false;}
try{
newWebDriverWait(driver,timeOutInSeconds,100).until(newExpectedCondition()?{
@Nullable
@Override
publicWebElementapply(@NullableWebDriver?driver)?{
if(isExist(webElement))?{
returnwebElement;
}else{
return?null;}}});
return?true;
}catch(Exception?e)?{
return?false;}}
7侵状、手勢(shì)解鎖
final?TouchAction?gesture?=?new?TouchAction(driver).press(startX,?stratY)???????
? .moveTo(startX,?stratY?+?height)
.moveTo(startX,?stratY?+?height?+?height)
.moveTo(startX?+?width,?stratY?+?height?+?height).release();
gesture.perform();
8赞弥、移動(dòng)到內(nèi)容最后刪除內(nèi)容
private void ReplaceEdittext(WebElement editext,Strings){
editext.click();
//獲取內(nèi)容
String context=driver.findElementByAccessibilityId("A").getAttribute("A");
//光標(biāo)移到末尾
driver.sendKeyEvent(123);
for (int i = 0; i < context.length(); i++) {
//刪除
driver.sendKeyEvent(AndroidKeyCode.DEL);
}
editext.sendKeys(s);
//回車
//driver.sendKeyEvent(66);
}
TouchAction
AppiumDriver的輔助類,主要針對(duì)手勢(shì)操作趣兄,比如滑動(dòng)绽左、長(zhǎng)按、拖動(dòng)等
9艇潭、press(WebElement el)在控件上執(zhí)行press操作拼窥。
10、press(int x, int y)在坐標(biāo)為(x,y)的點(diǎn)執(zhí)行press操作
11蹋凝、press(WebElement el, int x, int y)在控件el的左上角的x坐標(biāo)偏移x單位鲁纠,y左邊偏移y單位的坐標(biāo)上執(zhí)行press操作。
12鳍寂、moveTo(WebElement el)以el為目標(biāo)改含,從另一個(gè)點(diǎn)移動(dòng)到該目標(biāo)上。
13迄汛、moveTo(int x, int y)以(x,y)點(diǎn)為目標(biāo)捍壤,從另一個(gè)點(diǎn)移動(dòng)到該目標(biāo)上骤视。
14、moveTo(WebElement el, intx, int y)
以控件el的左上角為基準(zhǔn)白群,x軸向右移動(dòng)x單位尚胞,y軸向下移動(dòng)y單位。以該點(diǎn)為目標(biāo)帜慢,從另一個(gè)點(diǎn)移動(dòng)到該點(diǎn)上笼裳。
15、tap(WebElement el)
在控件的中心點(diǎn)上敲擊一下
16粱玲、tap(int x, int y)
在(x,y)點(diǎn)輕擊一下
17躬柬、tap(WebElement el, int x,int y)
以控件el的左上角為基準(zhǔn),x軸向右移動(dòng)x單位抽减,y軸向下移動(dòng)y單位允青。在該點(diǎn)上輕擊。
18卵沉、longPress(WebElement el)
控件長(zhǎng)按
19颠锉、longPress(int x, int y)點(diǎn)長(zhǎng)按
20、longPress(WebElement el, int x, int y)
偏移點(diǎn)長(zhǎng)按
21史汗、cancel()取消執(zhí)行該動(dòng)作
22琼掠、perform()執(zhí)行該動(dòng)作