Skip to content

Commit

Permalink
Upgrade to Selenium 4.22.0; use remote HtmlUnitDriver (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbabcoc authored Jul 14, 2024
1 parent 7dd8352 commit a7c9ad1
Show file tree
Hide file tree
Showing 39 changed files with 291 additions and 162 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ repositories {

dependencies {
constraints {
api 'com.nordstrom.tools:java-utils:3.1.1'
api 'com.nordstrom.tools:java-utils:3.2.1'
api 'com.nordstrom.tools:settings:3.0.5'
api 'com.nordstrom.tools:junit-foundation:17.0.4'
api 'com.nordstrom.tools:junit-foundation:17.1.1'
api 'com.github.sbabcoc:logback-testng:2.0.0'
api 'org.hamcrest:hamcrest-core:2.2'
api 'org.yaml:snakeyaml:1.33'
Expand Down
4 changes: 1 addition & 3 deletions htmlunitDeps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ System.setProperty('selenium.browser.name', 'htmlunit')
System.setProperty('selenium.context.platform', 'web-app')
dependencies {
if ("${profile}" == "selenium4") {
testImplementation('org.seleniumhq.selenium:htmlunit3-driver') {
exclude module: 'selenium-support'
}
testImplementation 'com.nordstrom.ui-tools:htmlunit-remote'
} else {
testImplementation('org.seleniumhq.selenium:htmlunit-driver') {
exclude module: 'selenium-support'
Expand Down
4 changes: 1 addition & 3 deletions selenium3Deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sourceSets {

dependencies {
constraints {
api 'com.nordstrom.tools:testng-foundation:4.0.4-j8'
api 'com.nordstrom.tools:testng-foundation:5.1.1-j8'
api 'org.seleniumhq.selenium:selenium-server:3.141.59'
api 'org.seleniumhq.selenium:selenium-support:3.141.59'
api 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'
Expand All @@ -38,7 +38,6 @@ dependencies {
api 'org.apache.httpcomponents:httpclient:4.5.14'
api 'org.jsoup:jsoup:1.15.3'
api 'org.apache.commons:commons-lang3:3.12.0'
api 'com.google.guava:guava:31.1-jre'
api 'com.beust:jcommander:1.82'
api 'com.squareup.okhttp3:okhttp:4.10.0'
api 'com.squareup.okio:okio:2.10.0'
Expand All @@ -57,7 +56,6 @@ dependencies {
api 'org.apache.httpcomponents:httpclient'
api 'org.jsoup:jsoup'
api 'org.apache.commons:commons-lang3'
api 'com.google.guava:guava'
api 'com.beust:jcommander'
api 'com.squareup.okhttp3:okhttp'
api 'com.squareup.okio:okio'
Expand Down
23 changes: 10 additions & 13 deletions selenium4Deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,22 @@ sourceSets {

dependencies {
constraints {
api 'com.nordstrom.tools:testng-foundation:4.0.4-j8'
api 'org.seleniumhq.selenium:selenium-grid:4.19.0'
api 'org.seleniumhq.selenium:selenium-support:4.19.0'
api 'org.seleniumhq.selenium:selenium-chrome-driver:4.19.0'
api 'org.seleniumhq.selenium:selenium-edge-driver:4.19.0'
api 'org.seleniumhq.selenium:selenium-firefox-driver:4.19.0'
api 'com.nordstrom.tools:testng-foundation:5.1.1-j11'
api 'org.seleniumhq.selenium:selenium-grid:4.22.0'
api 'org.seleniumhq.selenium:selenium-support:4.22.0'
api 'org.seleniumhq.selenium:selenium-chrome-driver:4.22.0'
api 'org.seleniumhq.selenium:selenium-edge-driver:4.22.0'
api 'org.seleniumhq.selenium:selenium-firefox-driver:4.22.0'
api 'org.seleniumhq.selenium:selenium-opera-driver:4.4.0'
api 'org.seleniumhq.selenium:selenium-safari-driver:4.19.0'
api 'org.seleniumhq.selenium:htmlunit3-driver:4.18.1'
api 'org.seleniumhq.selenium:selenium-safari-driver:4.22.0'
api 'com.nordstrom.ui-tools:htmlunit-remote:4.22.0'
api 'org.seleniumhq.selenium:htmlunit3-driver:4.22.0'
api 'org.htmlunit:htmlunit:4.2.0'
api 'com.codeborne:phantomjsdriver:1.5.0'
api 'org.apache.httpcomponents:httpclient:4.5.14'
api 'org.eclipse.jetty:jetty-servlet:9.4.50.v20221201'
api 'org.jsoup:jsoup:1.15.3'
api 'org.apache.commons:commons-lang3:3.12.0'
api ('com.google.guava:guava') {
version { strictly '31.1-jre' }
}
api 'com.beust:jcommander:1.82'
api 'io.netty:netty-transport-native-epoll:4.1.93.Final'
api 'io.netty:netty-transport-native-kqueue:4.1.93.Final'
Expand All @@ -54,8 +53,6 @@ dependencies {
api 'org.eclipse.jetty:jetty-servlet'
api 'org.jsoup:jsoup'
api 'org.apache.commons:commons-lang3'
api 'com.google.guava:guava'
api 'com.beust:jcommander'
api 'org.seleniumhq.selenium:htmlunit3-driver' // temporary
testImplementation 'org.mockito:mockito-core'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.io.FileHandler;
import org.apache.commons.configuration2.io.FileLocationStrategy;
Expand All @@ -29,9 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.io.Resources;
import com.nordstrom.automation.selenium.core.GridUtility;
import com.nordstrom.automation.selenium.core.SeleniumGrid;
import com.nordstrom.automation.selenium.servlet.ExamplePageLauncher;
Expand Down Expand Up @@ -589,8 +589,9 @@ public String resolveString(String propertyName) {
try {
// load contents of value file
Path path = Paths.get(valuePath);
URL url = path.toUri().toURL();
propertyValue = Resources.toString(url, Charsets.UTF_8);
try (Stream<String> lines = Files.lines(path)) {
propertyValue = lines.collect(Collectors.joining("\n"));
}
} catch (IOException eaten) {
// nothing to do here
}
Expand Down Expand Up @@ -652,6 +653,8 @@ public boolean shutdownGrid(final boolean localOnly) throws InterruptedException
ExamplePageLauncher.getLauncher().shutdown();
seleniumGrid = null;
}
} else {
ExamplePageLauncher.getLauncher().shutdown();
}
return result;
}
Expand Down Expand Up @@ -755,9 +758,9 @@ public Capabilities getCurrentCapabilities() {
Capabilities capabilities = null;
String browserName = getString(SeleniumSettings.BROWSER_NAME.key());
String browserCaps = resolveString(SeleniumSettings.BROWSER_CAPS.key());
if (!Strings.isNullOrEmpty(browserName)) {
if (!(browserName == null || browserName.isEmpty())) {
capabilities = getSeleniumGrid().getPersonality(getConfig(), browserName);
} else if (!Strings.isNullOrEmpty(browserCaps)) {
} else if (!(browserCaps == null || browserCaps.isEmpty())) {
capabilities = getCapabilitiesForJson(browserCaps)[0];
} else {
throw new IllegalStateException("Neither browser name nor capabilities are specified");
Expand Down Expand Up @@ -962,7 +965,7 @@ public Set<String> getHubServlets() {
// get specified hub servlet classes
String hubServlets = getString(SeleniumSettings.HUB_SERVLETS.key());
// if servlets are specified
if ( ! Strings.isNullOrEmpty(hubServlets)) {
if (!(hubServlets == null || hubServlets.isEmpty())) {
// collect servlet names, minus leading/trailing white space
servlets.addAll(Arrays.asList(hubServlets.trim().split("\\s*,\\s*")));
}
Expand All @@ -988,7 +991,7 @@ public Set<String> getNodeServlets() {
// get specified node servlet classes
String nodeServlets = getString(SeleniumSettings.NODE_SERVLETS.key());
// if servlets are specified
if ( ! Strings.isNullOrEmpty(nodeServlets)) {
if (!(nodeServlets == null || nodeServlets.isEmpty())) {
// collect servlet names, minus leading/trailing white space
servlets.addAll(Arrays.asList(nodeServlets.trim().split("\\s*,\\s*")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.lang.reflect.Method;
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
Expand All @@ -11,8 +13,6 @@
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.support.ui.FluentWait;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.nordstrom.automation.selenium.AbstractSeleniumConfig.SeleniumSettings;
import com.nordstrom.automation.selenium.AbstractSeleniumConfig.WaitType;
import com.nordstrom.automation.selenium.SeleniumConfig;
Expand Down Expand Up @@ -200,7 +200,7 @@ public static Optional<WebDriver> nabDriver(final Object obj) {
if (obj instanceof TestBase) {
return ((TestBase) obj).nabDriver();
} else {
return Optional.absent();
return Optional.empty();
}
}

Expand All @@ -227,7 +227,7 @@ public static Optional<SessionId> getSessionId(final WebDriver driver) {
SessionId sessionId = ((RemoteWebDriver) driver).getSessionId();
return Optional.of(sessionId);
}
return Optional.absent();
return Optional.empty();
}

/**
Expand All @@ -242,7 +242,7 @@ public static Optional<WebDriver> closeDriver(final Object obj) {
WebDriver driver = optDriver.get();

try {
((JavascriptExecutor) driver).executeScript("return window.stop");
((JavascriptExecutor) driver).executeScript("window.stop();");
} catch (WebDriverException | UnsupportedOperationException eaten) {
// Let's make sure our graceful shutdown process doesn't cause failures.
}
Expand All @@ -255,7 +255,7 @@ public static Optional<WebDriver> closeDriver(final Object obj) {

((TestBase) obj).setInitialPage(null);
((TestBase) obj).setDriver(null);
optDriver = Optional.absent();
optDriver = Optional.empty();
driver.quit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableList;
import com.nordstrom.automation.selenium.AbstractSeleniumConfig.SeleniumSettings;
import com.nordstrom.automation.selenium.DriverPlugin;
import com.nordstrom.automation.selenium.SeleniumConfig;
Expand Down Expand Up @@ -357,13 +356,12 @@ private static <T extends RemoteWebDriver> Constructor<T> getRemoteWebDriverCtor
* @return list of driver plugin instances
*/
public static List<DriverPlugin> getDriverPlugins(SeleniumConfig config) {
List<DriverPlugin> driverPlugins;
List<DriverPlugin> driverPlugins = new ArrayList<>();

// get grid plugins setting
String gridPlugins = config.getString(SeleniumSettings.GRID_PLUGINS.key());
// if setting is defined and not empty
if ( ! (gridPlugins == null || gridPlugins.trim().isEmpty())) {
driverPlugins = new ArrayList<>();
// iterate specified driver plugin class names
for (String driverPlugin : gridPlugins.split(File.pathSeparator)) {
String className = driverPlugin.trim();
Expand Down Expand Up @@ -394,7 +392,7 @@ public static List<DriverPlugin> getDriverPlugins(SeleniumConfig config) {
// get service loader for driver plugins
ServiceLoader<DriverPlugin> serviceLoader = ServiceLoader.load(DriverPlugin.class);
// collect list of configured plugins
driverPlugins = ImmutableList.copyOf(serviceLoader.iterator());
serviceLoader.iterator().forEachRemaining(driverPlugins::add);
}

return driverPlugins;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.nordstrom.automation.selenium.core;

import static java.nio.charset.StandardCharsets.UTF_8;
import static com.nordstrom.automation.selenium.servlet.ExamplePageServlet.readAllBytes;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand All @@ -21,8 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.nordstrom.automation.selenium.exceptions.DocumentNotReadyTimeoutException;
import com.nordstrom.automation.selenium.model.FirefoxShadowRoot;
import com.nordstrom.automation.selenium.support.Coordinator;
Expand Down Expand Up @@ -213,9 +214,11 @@ public static void injectGlueLib(final WebDriver driver) {
* @return resource file content
*/
public static String getScriptResource(final String resource) {
URL url = Resources.getResource(resource);
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
try {
return Resources.toString(url, Charsets.UTF_8);
try (InputStream is = classLoader.getResourceAsStream(resource)) {
return (is != null) ? new String(readAllBytes(is), UTF_8) : null;
}
} catch (IOException e) {
throw new IllegalArgumentException("Failed to load JavaScript resource '" + resource + "'", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.nordstrom.automation.selenium.core;

import java.lang.reflect.Method;
import java.util.Optional;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;

import com.google.common.base.Optional;
import com.nordstrom.automation.selenium.exceptions.DriverNotAvailableException;
import com.nordstrom.automation.selenium.exceptions.InitialPageNotSpecifiedException;
import com.nordstrom.automation.selenium.model.Page;
Expand Down Expand Up @@ -156,7 +156,7 @@ public static <T> Optional<T> optionalOf(T obj) {
if (obj != null) {
return Optional.of(obj);
} else {
return Optional.absent();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ public static URI setHubAsTarget() {
try {
// if running Selenium 4+
if (config.getVersion() > 3) {
// ensure example page servlet is running
ExamplePageLauncher.getLauncher().start();
// get URI of example page servlet
targetUri = ExamplePageLauncher.getLauncher().getUrl().toURI();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.nordstrom.automation.selenium.support.Coordinators;

/**
* This exception is associated with the {@link Coordinators#has(com.google.common.base.Function)} wrapper method
* This exception is associated with the {@link Coordinators#has(java.util.function.Function)} wrapper method
* and indicates that the wrapped condition was still returning a 'negative' result when the timeout interval expired.
*/
public class ConditionStillInvalidTimeoutException extends TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.nordstrom.automation.selenium.support.Coordinators;

/**
* This exception is associated with the {@link Coordinators#not(com.google.common.base.Function)} wrapper method
* This exception is associated with the {@link Coordinators#not(java.util.function.Function)} wrapper method
* and indicates that the wrapped condition was still returning a 'positive' result when the timeout interval expired.
*/
public class ConditionStillValidTimeoutException extends TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Method;
import java.util.Map;
import java.util.Optional;

import com.nordstrom.automation.junit.AtomIdentity;
import org.junit.After;
Expand All @@ -14,7 +15,6 @@
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.WebDriver;
import com.google.common.base.Optional;
import com.nordstrom.automation.junit.ArtifactParams;
import com.nordstrom.automation.selenium.core.TestBase;
import com.nordstrom.automation.selenium.model.Page;
Expand Down Expand Up @@ -149,6 +149,6 @@ public Description getDescription() {
*/
@Override
public Optional<Map<String, Object>> getParameters() {
return Optional.absent();
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.nordstrom.automation.selenium.junit;

import java.nio.file.Path;
import java.util.Optional;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nordstrom.automation.selenium.core.DriverManager;
import com.nordstrom.automation.selenium.utility.PageSourceUtils;
import com.google.common.base.Optional;
import com.nordstrom.automation.junit.ArtifactType;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.nordstrom.automation.selenium.junit;

import java.nio.file.Path;
import java.util.Optional;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nordstrom.automation.selenium.core.DriverManager;
import com.nordstrom.automation.selenium.utility.ScreenshotUtils;
import com.google.common.base.Optional;
import com.nordstrom.automation.junit.ArtifactType;

/**
Expand Down
Loading

0 comments on commit a7c9ad1

Please sign in to comment.