提交 3bda7a24 authored 作者: 孙洁清's avatar 孙洁清

Merge branch 'master' of git.yfzx.zjtys.com.cn:hct/auto-test

......@@ -144,7 +144,7 @@ public class SeleniumExecutor {
if (!success) {
String screenshotName = alterUrlName(currentUrl) + ".png";
screenshot(screenshotName);
screenshot = String.format("http://%s:%s/%s", screenshotPrefixHost, screenshotPrefixPort, screenshotName);
screenshot = String.format("/%s", screenshotName);
}
//总合信息
Set<String> messages = elementDetails.stream()
......@@ -197,7 +197,9 @@ public class SeleniumExecutor {
Map<Attributes, WebElement> reload = reload();
traversal(reload, elementDetails);
}
elementDetails.add(elementDetail);
if (nonNull(elementDetail)) {
elementDetails.add(elementDetail);
}
}
}
}
......@@ -205,9 +207,22 @@ public class SeleniumExecutor {
private ElementDetail act(Attributes attributes, WebElement element, String actType) {
String type = String.format("<%s>%s", element.getTagName(), element.getText());
String message = null;
long responseTime = 0L;
long responseTime = -1L;
boolean success = false;
try {
Boolean locationMatch = checkLocation(element);
if (!locationMatch) {
message = "布局错误";
log.error("error:布局错误");
historyAttributes.add(attributes);
currentHistoryAttributes.add(attributes);
return new ElementDetail(
type,
(int) responseTime,
false,
message
);
}
if (isEnabled(element)) {
long startTime = System.currentTimeMillis();
if (Objects.equals(actType, INPUT)) {
......@@ -225,29 +240,25 @@ public class SeleniumExecutor {
}
long endTime = System.currentTimeMillis();
responseTime = endTime - startTime;
Alert alert = ExpectedConditions.alertIsPresent().apply(driver);
String jsMsg = checkJsError();
if (nonNull(alert)) {
message = "出现警告窗:" + alert.getText();
message = "error:出现警告窗:" + alert.getText();
alert.accept();
success = false;
}
String jsMsg = checkJsError();
if (nonNull(jsMsg)) {
} else if (nonNull(jsMsg)) {
message = jsMsg;
success = false;
log.error("error:出现js异常:{}", jsMsg);
}
}
} catch (ElementNotInteractableException e) {
message = "布局错误";
success = false;
log.error("error:存在可操作范围之外的元素");
log.error("error:可操作范围之外的元素");
return null;
} catch (TimeoutException e) {
message = "页面超时";
success = false;
log.error("error:存在可操作范围之外的元素");
log.error("error:页面超时");
} catch (NoSuchElementException e) {
message = "依赖缺失";
success = false;
......@@ -435,6 +446,19 @@ public class SeleniumExecutor {
return result;
}
private Boolean checkLocation(WebElement element) {
try {
Dimension size = driver.manage().window().getSize();
Point elementLocation = element.getLocation();
Dimension elementSize = element.getSize();
boolean xMatch = (elementLocation.x) >= 0 && (elementLocation.x + elementSize.width <= size.width);
boolean yMatch = (elementLocation.y) >= 0 && (elementLocation.y + elementSize.width <= size.height);
return xMatch && yMatch;
} catch (Exception e) {
return false;
}
}
@SuppressWarnings("OptionalGetWithoutIsPresent")
private String checkJsError() {
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论