Skip to content

Commit 413acc4

Browse files
committed
Include getResolvedBrowserVersion() in the WebDriverManager API (#1474)
1 parent 2c982a6 commit 413acc4

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/doc/asciidoc/index.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ include::../../test/java/io/github/bonigarcia/wdm/test/generic/GenericTest.java[
131131
The driver management provided by WebDriverManager can be tuned in many different ways. For example, the WebDriverManager API allows configuring the driver (or browser) version to be resolved, the location of the cache path, the operating system, the architecture, the proxy settings (for the network connection), the TTL, or cleaning the driver and resolution cache, among many other attributes. See the <<advanced-configuration,advanced configuration>> settings for specific details about it. In addition, there are several WebDriverManager API methods specific to driver management, namely:
132132

133133
* `getDownloadedDriverPath()`: Used to find out the path of the resolved driver in the current instance of WebDriverManager.
134-
* `getDownloadedDriverVersion()`: Use to find out the version of the driver resolved in the current instance of WebDriverManager.
134+
* `getDownloadedDriverVersion()`: Used to find out the version of the driver resolved in the current instance of WebDriverManager.
135+
* `getResolvedBrowserVersion()`: Used to find out the major browser version discovered in the current instance of WebDriverManager.
135136
* `getDriverVersions()`: Used to find the list of available driver versions in a given manager.
136137
* `getDriverManagerType()`: Used to get the driver manager type (and `enum`) of a given manager.
137138

src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ public String getDownloadedDriverVersion() {
860860
return downloadedDriverVersion;
861861
}
862862

863+
public String getResolvedBrowserVersion() {
864+
return resolvedBrowserVersion;
865+
}
866+
863867
public List<String> getDriverVersions() {
864868
List<String> driverVersionList = new ArrayList<>();
865869
try {

src/test/java/io/github/bonigarcia/wdm/test/versions/BrowserVersionTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.slf4j.LoggerFactory.getLogger;
2222

2323
import java.io.File;
24+
import java.util.Optional;
2425

2526
import org.junit.jupiter.api.Test;
2627
import org.slf4j.Logger;
@@ -37,18 +38,29 @@ class BrowserVersionTest {
3738

3839
final Logger log = getLogger(lookup().lookupClass());
3940

41+
@Test
42+
void testChromeLatestVersion() {
43+
WebDriverManager wdm = WebDriverManager.chromedriver();
44+
wdm.setup();
45+
assertBrowserVersion(wdm, Optional.empty());
46+
}
47+
4048
@Test
4149
void testChromeVersion() {
4250
WebDriverManager wdm = WebDriverManager.chromedriver();
43-
wdm.browserVersion("91").avoidResolutionCache().setup();
51+
String browserVersion = "91";
52+
wdm.browserVersion(browserVersion).avoidResolutionCache().setup();
4453
assertDriver(wdm);
54+
assertBrowserVersion(wdm, Optional.of(browserVersion));
4555
}
4656

4757
@Test
4858
void testFirefoxVersion() {
4959
WebDriverManager wdm = WebDriverManager.firefoxdriver();
50-
wdm.browserVersion("90").avoidResolutionCache().setup();
60+
String browserVersion = "90";
61+
wdm.browserVersion(browserVersion).avoidResolutionCache().setup();
5162
assertDriver(wdm);
63+
assertBrowserVersion(wdm, Optional.of(browserVersion));
5264
}
5365

5466
private void assertDriver(WebDriverManager wdm) {
@@ -57,4 +69,16 @@ private void assertDriver(WebDriverManager wdm) {
5769
assertThat(driver).exists();
5870
}
5971

72+
private void assertBrowserVersion(WebDriverManager wdm,
73+
Optional<String> expectedBrowserVersion) {
74+
String resolvedBrowserVersion = wdm.getResolvedBrowserVersion();
75+
log.debug("Resolved browser version {}", resolvedBrowserVersion);
76+
assertThat(resolvedBrowserVersion).isNotNull();
77+
78+
if (expectedBrowserVersion.isPresent()) {
79+
assertThat(expectedBrowserVersion.get())
80+
.isEqualTo(resolvedBrowserVersion);
81+
}
82+
}
83+
6084
}

0 commit comments

Comments
 (0)