Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 2ba9f8d

Browse files
committed
搜索策略添加描述接口
1 parent cb52777 commit 2ba9f8d

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/main/java/org/suren/autotest/web/framework/core/ElementSearchStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ public interface ElementSearchStrategy<T>
1414
* @return
1515
*/
1616
T search(Element element);
17+
18+
/**
19+
* @return 当前策略的描述信息
20+
*/
21+
String description();
1722
}

src/main/java/org/suren/autotest/web/framework/selenium/strategy/CyleSearchStrategy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ private WebElement findElement(By by)
108108
return engine.getDriver().findElement(by);
109109
}
110110

111+
@Override
112+
public String description()
113+
{
114+
return "循环元素定位搜索策略。";
115+
}
116+
111117
}

src/main/java/org/suren/autotest/web/framework/selenium/strategy/PrioritySearchStrategy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,11 @@ public void setParent(WebElement parentWebElement)
224224
{
225225
this.parentElement = parentWebElement;
226226
}
227+
228+
@Override
229+
public String description()
230+
{
231+
return "根据预先给定的元素定位方法优先级进行搜索,直到找到元素或者定位方法穷举完毕。"
232+
+ "如果元素指定了显式的查找超时时间,则采用可见性的超时等待。";
233+
}
227234
}

src/main/java/org/suren/autotest/web/framework/selenium/strategy/ZoneSearchStrategy.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ZoneSearchStrategy implements ElementSearchStrategy<WebElement>, Pa
3838

3939
private int failedCount = 0;
4040
private int maxFailed = 6;
41+
private int timeout = 1500;
4142

4243
private WebElement parentWebElement;
4344

@@ -114,7 +115,6 @@ private WebElement retry(AbstractLocator<WebElement> absLocator, SearchContext w
114115
}
115116
else
116117
{
117-
int timeout = 1500;
118118
logger.warn("Can not found element by locator {}, "
119119
+ "will retry locate again {} millis later, failed times {}.",
120120
absLocator, timeout, failedCount);
@@ -127,4 +127,11 @@ private WebElement retry(AbstractLocator<WebElement> absLocator, SearchContext w
127127
public void setParent(WebElement parentWebElement) {
128128
this.parentWebElement = parentWebElement;
129129
}
130+
131+
@Override
132+
public String description()
133+
{
134+
return String.format("区域搜索策略,按照元素的区域划分,分层次地进行多次定位搜索。每次元素查找失败,"
135+
+ "都会进行重试(%s次),每次失败后的超时时间为%s毫秒。", maxFailed, timeout);
136+
}
130137
}

0 commit comments

Comments
 (0)