提交 89b48347 authored 作者: 黄承天's avatar 黄承天

[feature]

增加按键操作 简化异常信息
上级 59ac5428
......@@ -12,6 +12,8 @@ public interface CommandType {
String TYPE = "type";
String SEND_KEYS = "sendKeys";
String MOUSE_OVER = "mouseOver";
String SET_WINDOW_SIZE = "setWindowSize";
......
......@@ -34,7 +34,7 @@ import static java.util.Objects.nonNull;
/**
* @author C
*/
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "Duplicates", "SpringJavaAutowiredFieldsWarningInspection", "DuplicateExpressions"})
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "Duplicates", "SpringJavaAutowiredFieldsWarningInspection"})
@Slf4j
@Service
public class SeleniumExecutor {
......@@ -239,7 +239,7 @@ public class SeleniumExecutor {
break;
case CLICK:
content = format("单击:[%s]", target);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -263,7 +263,7 @@ public class SeleniumExecutor {
break;
case DOUBLE_CLICK:
content = format("双击:[%s]", target);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -285,7 +285,7 @@ public class SeleniumExecutor {
break;
case MOUSE_DOWN:
content = format("长单击:[%s]", target);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -307,7 +307,7 @@ public class SeleniumExecutor {
break;
case MOUSE_MOVE:
content = format("鼠标移动至:[%s]", target);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -328,7 +328,7 @@ public class SeleniumExecutor {
break;
case MOUSE_UP:
content = format("停止长按:[%s]", target);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -350,7 +350,7 @@ public class SeleniumExecutor {
case SELECT:
String label = seleniumHelper.getValue(value);
content = format("下拉框选择:[%s]", label);
waitForELement(target,targets);
waitForELement(target, targets);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
......@@ -396,6 +396,19 @@ public class SeleniumExecutor {
success = false;
}
break;
case SEND_KEYS:
content = format("输入按键:[%s]", value);
element = getElement(target, targets);
costTime = System.currentTimeMillis() - stepStartTime;
if (nonNull(element)) {
String key = seleniumHelper.getKeyForSend(value);
element.sendKeys(Keys.valueOf(key));
success = true;
} else {
message = "无法定位该元素";
success = false;
}
break;
case CLOSE:
content = "关闭窗口";
try {
......@@ -413,7 +426,7 @@ public class SeleniumExecutor {
} catch (Exception e) {
log.error(e.getLocalizedMessage());
Arrays.stream(e.getStackTrace()).forEach(System.out::println);
message = e.getLocalizedMessage();
message = format("出现异常:%s",e.getClass().getSimpleName());
success = false;
}
stepStartTime = System.currentTimeMillis();
......@@ -440,16 +453,15 @@ public class SeleniumExecutor {
}
private void movetoElementView(WebElement element) {
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].scrollIntoView(true);", element);
}
private void waitForELement(String target, List<List<String>> targets){
private void waitForELement(String target, List<List<String>> targets) {
try {
new WebDriverWait(driver,3).until(webDriver -> nonNull(getElement(target,targets)));
} catch (Exception ignored){
new WebDriverWait(driver, 3).until(webDriver -> nonNull(getElement(target, targets)));
} catch (Exception ignored) {
}
}
......@@ -468,7 +480,7 @@ public class SeleniumExecutor {
}
}
return null;
}else {
} else {
return element;
}
}
......
......@@ -46,6 +46,10 @@ public class SeleniumHelper {
return name_value[1];
}
public String getKeyForSend(String value) {
return value.replace("${KEY_", "").replace("}", "");
}
private Map<String, String> handleMap = new HashMap<>();
private Set<String> historyHandles = new HashSet<>();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论