滑动解锁
parent
1d160ef98d
commit
c05ca15444
|
@ -1634,6 +1634,57 @@ public class CommonTools {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Keyword(alias = "滑动解锁", category = "0", attributes = "4")
|
||||||
|
@Return(name = "result", comment = "手机滑动", type = DataType.BOOLEAN)
|
||||||
|
public Boolean pressAndSwipe(
|
||||||
|
IExecuteContext context,
|
||||||
|
@Argument(name = "__deviceDriver", scope = ParamScope.CONTEXT, comment = "设备连接", type = DataType.OBJECT) DeviceDriver deviceDriver,
|
||||||
|
@Argument(name = "targets", scope = ParamScope.STEP, comment = "控件位置", type = DataType.LIST, defaultDisplay = false) List<IStepTarget> targets,
|
||||||
|
@Argument(name = "passingPoints", scope = ParamScope.ARGS, comment = "经过的点", type = DataType.LIST, defaultDisplay = true) List<Integer> passingPoints,
|
||||||
|
@Argument(name = "waitTime", scope = ParamScope.ARGS, comment = "等待时间(单位s)", type = DataType.INTEGER, defaultValue = "30") Integer waitTime,
|
||||||
|
@Argument(name = "preExecuteWait", scope = ParamScope.ARGS, comment = "执行前等待(单位:s)", type = DataType.INTEGER, required = false, defaultValue = "1.0", defaultDisplay = false) Float preExecuteWait,
|
||||||
|
@Argument(name = "sufExecuteWait", scope = ParamScope.ARGS, comment = "执行后等待(单位:s)", type = DataType.INTEGER, required = false, defaultValue = "1.0", defaultDisplay = false) Float sufExecuteWait
|
||||||
|
) {
|
||||||
|
PressAndSwipeThread monkeyTestThread = new PressAndSwipeThread(deviceDriver,targets,passingPoints,preExecuteWait,sufExecuteWait);
|
||||||
|
Future<Boolean> future = executorService.submit(monkeyTestThread);
|
||||||
|
Boolean result = null;
|
||||||
|
deviceDriver.setFuture(future);
|
||||||
|
int count = targets.size();
|
||||||
|
try {
|
||||||
|
result = future.get(waitTime*count, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.warn("该线程被中断了。。。。。。");
|
||||||
|
throw new ExecuteException("执行中断");
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
logger.warn("在执行的时候报错了。。。。");
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause instanceof ExecuteException) {
|
||||||
|
ExecuteException ee = (ExecuteException) cause;
|
||||||
|
throw ee;
|
||||||
|
} else if (cause instanceof ParamMistakeException) {
|
||||||
|
ParamMistakeException pe = (ParamMistakeException) cause;
|
||||||
|
throw pe;
|
||||||
|
} else if (cause instanceof NoSuchSessionException) {
|
||||||
|
NoSuchSessionException ne = (NoSuchSessionException) cause;
|
||||||
|
throw ne;
|
||||||
|
} else if (cause instanceof EnvironmentException) {
|
||||||
|
EnvironmentException ee = (EnvironmentException) cause;
|
||||||
|
throw ee;
|
||||||
|
}else{
|
||||||
|
logger.error("出现了其他的问题。。。。");
|
||||||
|
throw new ExecuteException(cause.getMessage());
|
||||||
|
}
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
logger.warn("处理超时了。。。。。。");
|
||||||
|
throw new ExecuteException("输入超时");
|
||||||
|
} catch (CancellationException e) {
|
||||||
|
logger.warn("该操作被取消了");
|
||||||
|
throw new ExecuteException("用户取消,执行失败");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setParamValue(IExecuteContext context, String variable, String value) {
|
private void setParamValue(IExecuteContext context, String variable, String value) {
|
||||||
try {
|
try {
|
||||||
if (variable.contains("#{") && variable.contains("}")) {
|
if (variable.contains("#{") && variable.contains("}")) {
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package net.northking.cctp.element.mobile.thread;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import io.appium.java_client.AppiumDriver;
|
||||||
|
import net.northking.cctp.element.core.DeviceDriver;
|
||||||
|
import net.northking.cctp.element.core.IExecuteContext;
|
||||||
|
import net.northking.cctp.element.core.IStepTarget;
|
||||||
|
import net.northking.cctp.element.core.exception.ExecuteException;
|
||||||
|
import net.northking.cctp.element.mobile.constants.UsingType;
|
||||||
|
import net.northking.cctp.element.mobile.entity.PointMessage;
|
||||||
|
import net.northking.cctp.element.mobile.utils.CommonUtils;
|
||||||
|
import net.northking.cctp.element.mobile.utils.phoneUtils.ElementUtil;
|
||||||
|
import net.northking.cctp.element.mobile.utils.phoneUtils.HandleUtils;
|
||||||
|
import net.northking.cctp.element.mobile.utils.phoneUtils.ScreenUtil;
|
||||||
|
import org.openqa.selenium.Point;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.interactions.PointerInput;
|
||||||
|
import org.openqa.selenium.interactions.Sequence;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
public class PressAndSwipeThread implements Callable<Boolean> {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(PressAndSwipeThread.class);
|
||||||
|
|
||||||
|
private DeviceDriver deviceDriver;
|
||||||
|
private List<Integer> passingPoints;
|
||||||
|
private Float preExecuteWait;
|
||||||
|
private Float sufExecuteWait;
|
||||||
|
private List<IStepTarget> targets;
|
||||||
|
|
||||||
|
public PressAndSwipeThread(DeviceDriver deviceDriver, List<IStepTarget> targets,List<Integer> passingPoints, Float preExecuteWait, Float sufExecuteWait) {
|
||||||
|
this.deviceDriver = deviceDriver;
|
||||||
|
this.targets = targets;
|
||||||
|
this.passingPoints = passingPoints;
|
||||||
|
this.preExecuteWait = preExecuteWait;
|
||||||
|
this.sufExecuteWait = sufExecuteWait;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
CommonUtils.handlePreExecuteWait(preExecuteWait);
|
||||||
|
AppiumDriver<WebElement> driver = (AppiumDriver<WebElement>) deviceDriver;
|
||||||
|
WebElement webElement = null;
|
||||||
|
for (IStepTarget target : targets) {
|
||||||
|
if (UsingType.SELECTOR.equalsIgnoreCase(target.getUsing())) {
|
||||||
|
webElement = ElementUtil.findWebElementByXpath(driver, target, 30, true, "0", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null == webElement) {
|
||||||
|
throw new ExecuteException("未找到解锁的滑动区域");
|
||||||
|
}
|
||||||
|
Point location = webElement.getLocation();
|
||||||
|
int x = location.getX();
|
||||||
|
int y = location.getY();
|
||||||
|
int width = webElement.getRect().width;
|
||||||
|
int height = webElement.getRect().height;
|
||||||
|
List<Map<String, Integer>> pointList = new ArrayList<>();
|
||||||
|
logger.info("手势区域,位置=>x:{},y:{},宽:{},高:{}",x,y,width,height);
|
||||||
|
int perWidth = width /3;
|
||||||
|
int perHeight = height /3;
|
||||||
|
int pointY = y - perHeight/2;
|
||||||
|
int n = 1;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
pointY = pointY + perHeight; //每一行的y坐标
|
||||||
|
int pointX = x - perWidth/2;
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
pointX = pointX + perWidth;
|
||||||
|
logger.info("第{}个点的坐标x:{},y:{}",n,pointX,pointY);
|
||||||
|
Map<String, Integer> point = new HashMap<>();
|
||||||
|
point.put("x", pointX);
|
||||||
|
point.put("y", pointY);
|
||||||
|
pointList.add(n-1,point);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CommonUtils.handleSufExecuteWait(sufExecuteWait);
|
||||||
|
ScreenUtil.pressAndSwipe(driver, pointList, passingPoints);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue