From e842eca2ab66ac19da5f8e85af12b50a2b37012e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 9 Sep 2024 22:38:16 +0200 Subject: [PATCH] Update to Selenium 4.24.0 (#96) +semver:feature * 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 --- azure-pipelines.yml | 39 +++++++++++-------- pom.xml | 12 +++--- .../core/elements/ElementFactory.java | 37 ++++++++++-------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 02768ad..c0a8b6e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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' @@ -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 diff --git a/pom.xml b/pom.xml index ada9a96..67a70fc 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 4.0.0-SNAPSHOT - 2.23.1 + 2.24.0 @@ -121,28 +121,28 @@ com.google.guava guava - 33.1.0-jre + 33.3.0-jre com.fasterxml.jackson.core jackson-databind - 2.17.0 + 2.17.2 org.seleniumhq.selenium selenium-java - 4.23.0 + 4.24.0 io.appium java-client - 9.2.3 + 9.3.0 test org.apache.commons commons-lang3 - 3.14.0 + 3.17.0 test diff --git a/src/main/java/aquality/selenium/core/elements/ElementFactory.java b/src/main/java/aquality/selenium/core/elements/ElementFactory.java index abbaa61..bb2701c 100644 --- a/src/main/java/aquality/selenium/core/elements/ElementFactory.java +++ b/src/main/java/aquality/selenium/core/elements/ElementFactory.java @@ -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 { @@ -87,16 +82,26 @@ public List findElements(By locator, String name, IEleme } catch (TimeoutException e) { throw new org.openqa.selenium.TimeoutException(e.getMessage()); } - List webElements = elementFinder.findElements(locator, state, ZERO_TIMEOUT); String namePrefix = name == null ? "element" : name; - List 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 elements = new ArrayList<>(); + Collection> ignoredExceptions = Arrays.asList( + StaleElementReferenceException.class, JavascriptException.class, org.openqa.selenium.TimeoutException.class + ); + conditionalWait.waitFor(() -> { + List 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 {