From f6d5a1cc2ad723d11b303cd818924e05cfae9c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 9 Sep 2024 21:23:59 +0200 Subject: [PATCH 1/4] Update to Selenium 4.24.0 +semver:feature Stabilize wait for FindElements in the ElementFactory --- pom.xml | 12 +++--- .../core/elements/ElementFactory.java | 37 +++++++++++-------- 2 files changed, 27 insertions(+), 22 deletions(-) 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 { From fb06a6425c292e79846e4df5994fda6850dc6733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 9 Sep 2024 22:02:00 +0200 Subject: [PATCH 2/4] Update to get rid of deprecated tasks from azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 02768ad..ba8f7b7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,33 +9,37 @@ 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' + options: '-Xmx3072m' 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' displayName: 'Run SonarCloud code analysis' continueOnError: true - - task: SonarCloudPublish@1 + - task: SonarCloudPublish@2 displayName: 'Publish SonarCloud quality gate results' inputs: pollingTimeoutSec: '300' @@ -89,14 +93,17 @@ 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' + options: '-Xmx3072m' 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 From a599d9b89b95b57e29ff2b333e23b6957e81adea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 9 Sep 2024 22:10:20 +0200 Subject: [PATCH 3/4] Update azure-pipelines.yml for Azure Pipelines: remove Xmx3072m option remove update of java heap space --- azure-pipelines.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ba8f7b7..04ba68d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,7 +23,6 @@ jobs: inputs: mavenPomFile: 'pom.xml' goals: 'clean' - options: '-Xmx3072m' publishJUnitResults: true testResultsFiles: '**/surefire-reports/TEST-*.xml' javaHomeOption: 'JDKVersion' @@ -98,7 +97,6 @@ jobs: inputs: mavenPomFile: 'pom.xml' goals: 'clean test -Dprofile=local' - options: '-Xmx3072m' publishJUnitResults: true testResultsFiles: '**/surefire-reports/TEST-*.xml' javaHomeOption: 'JDKVersion' From fce902472c73a9a77922f2b5eb5c6de6adc53528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 9 Sep 2024 22:15:28 +0200 Subject: [PATCH 4/4] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 04ba68d..c0a8b6e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -34,7 +34,7 @@ jobs: - task: SonarCloudAnalyze@2 inputs: - jdkversion: 'JAVA_HOME' + jdkversion: 'JAVA_HOME_21_X64' displayName: 'Run SonarCloud code analysis' continueOnError: true