Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Docker Image Cache Restore
id: docker-image-cache-restore
uses: xdev-software/tci/.github/actions/docker-image-cache/restore@f686d444930db567aae0cbc8076694f8c886f479 # v4.1.0
uses: xdev-software/tci/.github/actions/docker-image-cache/restore@5726976f1afd621ab01091ec6b0d7966bd4bb247 # v4.2.0
with:
# This cache could always change however because docker images can be changed remotely if the version is not fixated
# As a compromise it utilizes the hash of the pom files because when the dependencies stay the same
Expand Down Expand Up @@ -81,7 +81,9 @@ jobs:
fi

- name: Docker Image Cache Save
uses: xdev-software/tci/.github/actions/docker-image-cache/save@f686d444930db567aae0cbc8076694f8c886f479 # v4.1.0
uses: xdev-software/tci/.github/actions/docker-image-cache/save@5726976f1afd621ab01091ec6b0d7966bd4bb247 # v4.2.0
# Only save cache for one instance, otherwise they try to overwrite each other
if: ${{ matrix.java == 25 }}
with:
key: ${{ steps.docker-image-cache-restore.outputs.key }}
cache-hit: ${{ steps.docker-image-cache-restore.outputs.cache-hit }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.1.1
* Version detection: Use Selenium's `BuildInfo` when available

# 2.1.0
* Rename `SeleniumUtils` to `SeleniumVersionDetector`
* Extract image name extraction logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.xdev.testcontainers.selenium.containers.browser;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
Expand Down Expand Up @@ -63,6 +64,15 @@ public static synchronized String determineClasspathSeleniumVersion()
return cachedVersion;
}

try
{
return determineVersionUsingSeleniumBuildInfo();
}
catch(final Exception ex)
{
LOG.debug("Resolution using Selenium's built in BuildInfo failed, falling back to manifest", ex);
}

final Set<String> seleniumVersions = new HashSet<>();
try
{
Expand Down Expand Up @@ -112,6 +122,23 @@ public static synchronized String determineClasspathSeleniumVersion()
return foundVersion;
}

@SuppressWarnings("java:S112")
public static String determineVersionUsingSeleniumBuildInfo() throws Exception
{
final Class<?> buildInfoCl = Class.forName("org.openqa.selenium.BuildInfo");
final Method mGetReleaseLabel = buildInfoCl.getDeclaredMethod("getReleaseLabel");
final Object instance = buildInfoCl.getDeclaredConstructor().newInstance();

final String version = (String)mGetReleaseLabel.invoke(instance);
if(version == null || version.isEmpty() || "unknown".equals(version))
{
throw new IllegalStateException("Invalid version returned " + version);
}

LOG.info("Selenium API version {} detected using Selenium BuildInfo", version);
return version;
}

/**
* Read Manifest to get Selenium Version.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void simpleCheck(final Capabilities capabilities)
new RemoteWebDriver(browserContainer.getSeleniumAddressURI().toURL(), capabilities, false);

remoteWebDriver.manage().window().maximize();
remoteWebDriver.get(capabilities instanceof FirefoxOptions ? "about:support" : "chrome://version");
// Query file due to https://github.com/SeleniumHQ/selenium/issues/17905
remoteWebDriver.get("file:///proc/cpuinfo");
remoteWebDriver.findElements(By.tagName("body"));

remoteWebDriver.quit();
Expand Down
Loading