Skip to content

Commit

Permalink
Update to Selenium 4.24.0 (#96) +semver:feature
Browse files Browse the repository at this point in the history
* Update to Selenium 4.24.0 
Stabilize wait for FindElements in the ElementFactory

* Update to get rid of deprecated tasks from azure-pipelines.yml for Azure Pipelines, remove update of java heap space
  • Loading branch information
mialeska authored Sep 9, 2024
1 parent 6f0f4ac commit e842eca
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
39 changes: 22 additions & 17 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@ jobs:
displayName: Analyse code with SonarQube

steps:
- task: SonarCloudPrepare@1
- task: SonarCloudPrepare@2
displayName: 'Prepare SonarCloud analysis'
inputs:
SonarCloud: 'SonarCloud'
organization: 'aqualityautomation'
scannerMode: 'CLI'
configMode: 'file'
extraProperties: |
sonar.coverage.exclusions=**/**
extraProperties: 'sonar.coverage.exclusions=**/**'

- task: Maven@3
- task: Maven@4
displayName: 'Build project'
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '11'
jdkArchitectureOption: 'x64'
goals: 'clean'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false

- task: SonarCloudAnalyze@1
- task: SonarCloudAnalyze@2
inputs:
jdkversion: 'JAVA_HOME_21_X64'
displayName: 'Run SonarCloud code analysis'
continueOnError: true

- task: SonarCloudPublish@1
- task: SonarCloudPublish@2
displayName: 'Publish SonarCloud quality gate results'
inputs:
pollingTimeoutSec: '300'
Expand Down Expand Up @@ -89,14 +92,16 @@ jobs:
inputs:
displaySettings: 'optimal'

- task: Maven@3
- task: Maven@4
displayName: 'Run tests'
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '11'
jdkArchitectureOption: 'x64'
goals: 'clean test -Dprofile=local'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean test -Dprofile=local'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>4.0.0-SNAPSHOT</revision>
<log4j.version>2.23.1</log4j.version>
<log4j.version>2.24.0</log4j.version>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -121,28 +121,28 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.1.0-jre</version>
<version>33.3.0-jre</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.23.0</version>
<version>4.24.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.2.3</version>
<version>9.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<version>3.17.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/aquality/selenium/core/elements/ElementFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@
import aquality.selenium.core.logging.Logger;
import aquality.selenium.core.waitings.IConditionalWait;
import com.google.inject.Inject;
import org.openqa.selenium.By;
import org.openqa.selenium.*;
import org.openqa.selenium.By.ByTagName;
import org.openqa.selenium.By.ByXPath;
import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.ByChained;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeoutException;

public class ElementFactory implements IElementFactory {
Expand Down Expand Up @@ -87,16 +82,26 @@ public <T extends IElement> List<T> findElements(By locator, String name, IEleme
} catch (TimeoutException e) {
throw new org.openqa.selenium.TimeoutException(e.getMessage());
}
List<WebElement> webElements = elementFinder.findElements(locator, state, ZERO_TIMEOUT);
String namePrefix = name == null ? "element" : name;
List<T> list = new ArrayList<>();
for (int index = 1; index <= webElements.size(); index++) {
WebElement webElement = webElements.get(index - 1);
String currentName = String.format("%1$s %2$s", namePrefix, index);
T element = supplier.get(generateLocator(locator, webElement, index), currentName, state);
list.add(element);
}
return list;
List<T> elements = new ArrayList<>();
Collection<Class<? extends Throwable>> ignoredExceptions = Arrays.asList(
StaleElementReferenceException.class, JavascriptException.class, org.openqa.selenium.TimeoutException.class
);
conditionalWait.waitFor(() -> {
List<WebElement> webElements = elementFinder.findElements(locator, state, ZERO_TIMEOUT);
for (int index = 1; index <= webElements.size(); index++) {
WebElement webElement = webElements.get(index - 1);
String currentName = String.format("%1$s %2$s", namePrefix, index);
T element = supplier.get(generateLocator(locator, webElement, index), currentName, state);
elements.add(element);
}
boolean anyElementsFound = !elements.isEmpty();
return count == ElementsCount.ANY
|| (count == ElementsCount.ZERO && !anyElementsFound)
|| (count == ElementsCount.MORE_THAN_ZERO && anyElementsFound);
}, ignoredExceptions);

return elements;
}

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

0 comments on commit e842eca

Please sign in to comment.