进行结构分类
新增分类
WeChatSWeb 和 WeChatSWebElement 对将要进行操作的元素进行定义,定义好在进行进一步测业务操作
新增了屏幕进行滑动的方法,进行当前屏幕的滑动操作
protected void context(){
System.out.printf(dr.getContextHandles().toString());
dr.context(“WEBVIEW_com.tencent.mm:appbrand0”);
}
//通过direction 进行对屏幕上下左右滑动 进行滑动操作
protected void swipeToDirection(Direction direction,Integer edgeBorder){
// Animation default time:
// - Android: 300 ms
// - iOS: 200 ms
// final value depends on your app and could be greater
final int ANIMATION_TIME = 200; // ms
final int PRESS_TIME = 200; // ms
if(edgeBorder == null){
edgeBorder = 10;
}
PointOption pointOptionStart, pointOptionEnd;
// init screen variables
Dimension dimension = dr.manage().window().getSize();
pointOptionStart = PointOption.point(dimension.width / 2, dimension.height / 2);
switch (direction) {
case DOWN: // center of footer
pointOptionEnd = PointOption.point(dimension.width / 2, dimension.height - edgeBorder);
break;
case UP: // center of header
pointOptionEnd = PointOption.point(dimension.width / 2, edgeBorder);
break;
case LEFT: // center of left side
pointOptionEnd = PointOption.point(edgeBorder, dimension.height / 2);
break;
case RIGHT: // center of right side
pointOptionEnd = PointOption.point(dimension.width - edgeBorder, dimension.height / 2);
case TOP:
pointOptionEnd = PointOption.point(dimension.width/2, dimension.height);
case END:
pointOptionEnd = PointOption.point(dimension.width/2, 0);
break;
default:
throw new IllegalArgumentException("swipeScreen(): direction: '" + direction + "' NOT supported");
}
// execute swipe using TouchAction
try {
new TouchAction(dr)
.press(pointOptionStart)
// a bit more reliable when we add small wait
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME)))
.moveTo(pointOptionEnd)
.release().perform();
} catch (Exception e) {
System.err.println("swipeScreen(): TouchAction FAILED\n" + e.getMessage());
return;
}
// always allow swipe action to complete
try {
Thread.sleep(ANIMATION_TIME);
} catch (InterruptedException e) {
// ignore
}
}
public enum Direction {
TOP,
UP,
DOWN,
LEFT,
RIGHT,
END
}
对当前屏幕进行 滑动操作
发现元素时发现
WebElement webElement = dr.findElementByXPath(“元素内容”);
对此只能获取一个,在自己获取的页面一定是唯一的,不然获取就会报错
今天遇到一个问题:
就是chromedrvier 版本不对,微信小程序的chromedriver版本
chrome 应该是77版本,自己appium换成了 85版本,导致
dr.context(“WEBVIEW_com.tencent.mm:appbrand0”);
驱动不起来
要试试将chromedriver版本77试试