Skip to content

Commit f6d5a1c

Browse files
committed
Update to Selenium 4.24.0 +semver:feature
Stabilize wait for FindElements in the ElementFactory
1 parent 6f0f4ac commit f6d5a1c

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919
<revision>4.0.0-SNAPSHOT</revision>
20-
<log4j.version>2.23.1</log4j.version>
20+
<log4j.version>2.24.0</log4j.version>
2121
</properties>
2222

2323
<distributionManagement>
@@ -121,28 +121,28 @@
121121
<dependency>
122122
<groupId>com.google.guava</groupId>
123123
<artifactId>guava</artifactId>
124-
<version>33.1.0-jre</version>
124+
<version>33.3.0-jre</version>
125125
</dependency>
126126
<dependency>
127127
<groupId>com.fasterxml.jackson.core</groupId>
128128
<artifactId>jackson-databind</artifactId>
129-
<version>2.17.0</version>
129+
<version>2.17.2</version>
130130
</dependency>
131131
<dependency>
132132
<groupId>org.seleniumhq.selenium</groupId>
133133
<artifactId>selenium-java</artifactId>
134-
<version>4.23.0</version>
134+
<version>4.24.0</version>
135135
</dependency>
136136
<dependency>
137137
<groupId>io.appium</groupId>
138138
<artifactId>java-client</artifactId>
139-
<version>9.2.3</version>
139+
<version>9.3.0</version>
140140
<scope>test</scope>
141141
</dependency>
142142
<dependency>
143143
<groupId>org.apache.commons</groupId>
144144
<artifactId>commons-lang3</artifactId>
145-
<version>3.14.0</version>
145+
<version>3.17.0</version>
146146
<scope>test</scope>
147147
</dependency>
148148
</dependencies>

src/main/java/aquality/selenium/core/elements/ElementFactory.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88
import aquality.selenium.core.logging.Logger;
99
import aquality.selenium.core.waitings.IConditionalWait;
1010
import com.google.inject.Inject;
11-
import org.openqa.selenium.By;
11+
import org.openqa.selenium.*;
1212
import org.openqa.selenium.By.ByTagName;
1313
import org.openqa.selenium.By.ByXPath;
14-
import org.openqa.selenium.InvalidArgumentException;
15-
import org.openqa.selenium.WebElement;
1614
import org.openqa.selenium.support.pagefactory.ByChained;
1715

1816
import java.lang.reflect.Constructor;
1917
import java.lang.reflect.InvocationTargetException;
2018
import java.time.Duration;
21-
import java.util.ArrayList;
22-
import java.util.HashMap;
23-
import java.util.List;
24-
import java.util.Map;
19+
import java.util.*;
2520
import java.util.concurrent.TimeoutException;
2621

2722
public class ElementFactory implements IElementFactory {
@@ -87,16 +82,26 @@ public <T extends IElement> List<T> findElements(By locator, String name, IEleme
8782
} catch (TimeoutException e) {
8883
throw new org.openqa.selenium.TimeoutException(e.getMessage());
8984
}
90-
List<WebElement> webElements = elementFinder.findElements(locator, state, ZERO_TIMEOUT);
9185
String namePrefix = name == null ? "element" : name;
92-
List<T> list = new ArrayList<>();
93-
for (int index = 1; index <= webElements.size(); index++) {
94-
WebElement webElement = webElements.get(index - 1);
95-
String currentName = String.format("%1$s %2$s", namePrefix, index);
96-
T element = supplier.get(generateLocator(locator, webElement, index), currentName, state);
97-
list.add(element);
98-
}
99-
return list;
86+
List<T> elements = new ArrayList<>();
87+
Collection<Class<? extends Throwable>> ignoredExceptions = Arrays.asList(
88+
StaleElementReferenceException.class, JavascriptException.class, org.openqa.selenium.TimeoutException.class
89+
);
90+
conditionalWait.waitFor(() -> {
91+
List<WebElement> webElements = elementFinder.findElements(locator, state, ZERO_TIMEOUT);
92+
for (int index = 1; index <= webElements.size(); index++) {
93+
WebElement webElement = webElements.get(index - 1);
94+
String currentName = String.format("%1$s %2$s", namePrefix, index);
95+
T element = supplier.get(generateLocator(locator, webElement, index), currentName, state);
96+
elements.add(element);
97+
}
98+
boolean anyElementsFound = !elements.isEmpty();
99+
return count == ElementsCount.ANY
100+
|| (count == ElementsCount.ZERO && !anyElementsFound)
101+
|| (count == ElementsCount.MORE_THAN_ZERO && anyElementsFound);
102+
}, ignoredExceptions);
103+
104+
return elements;
100105
}
101106

102107
protected void waitForElementsCount(By locator, ElementsCount count, ElementState state) throws TimeoutException {

0 commit comments

Comments
 (0)