提交 16b7afc3 authored 作者: 黄承天's avatar 黄承天

改进元素Map匹配机制

上级 5a9d50e2
...@@ -104,6 +104,7 @@ public class SeleniumExecutor { ...@@ -104,6 +104,7 @@ public class SeleniumExecutor {
driver.close(); driver.close();
checkWindow(); checkWindow();
} }
driver.quit();
return new Report( return new Report(
null, null,
project.getId(), project.getId(),
...@@ -340,10 +341,8 @@ public class SeleniumExecutor { ...@@ -340,10 +341,8 @@ public class SeleniumExecutor {
for (int i = 0; i < webElements.size(); i++) { for (int i = 0; i < webElements.size(); i++) {
WebElement webElement = webElements.get(i); WebElement webElement = webElements.get(i);
Element jElement = jElements.get(i); Element jElement = jElements.get(i);
if (elementMatch(webElement, jElement)) {
result.put(jElement.attributes(), webElement); result.put(jElement.attributes(), webElement);
} }
}
return result; return result;
} }
...@@ -406,27 +405,8 @@ public class SeleniumExecutor { ...@@ -406,27 +405,8 @@ public class SeleniumExecutor {
} }
private Boolean elementMatch(WebElement webElement, Element element) { private Boolean elementMatch(WebElement webElement, Element element) {
try { return element.attributes().asList().stream()
boolean attributesMatch = element.attributes().asList().stream()
.allMatch(attribute -> Objects.equals(attribute.getValue(), webElement.getAttribute(attribute.getKey()))); .allMatch(attribute -> Objects.equals(attribute.getValue(), webElement.getAttribute(attribute.getKey())));
boolean tagMatch = Objects.equals(webElement.getTagName(), element.tagName());
boolean textMatch = Objects.equals(webElement.getText(), element.text());
if (element.attributes().isEmpty()) {
if (element.hasText()) {
return tagMatch && textMatch;
} else {
return tagMatch;
}
} else {
if (element.hasText()) {
return attributesMatch && tagMatch && textMatch;
} else {
return attributesMatch && tagMatch;
}
}
} catch (StaleElementReferenceException e) {
return false;
}
} }
private Map<Attributes, WebElement> removeHistoryElements(Map<Attributes, WebElement> elements) { private Map<Attributes, WebElement> removeHistoryElements(Map<Attributes, WebElement> elements) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论