Skip to content

Commit

Permalink
Use online geckodriver-support.json to discover geckodriver versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Feb 21, 2024
1 parent ea10efb commit c2880ad
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/main/java/io/github/bonigarcia/wdm/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public class Config {
URL.class);
ConfigKey<URL> firefoxDriverMirrorUrl = new ConfigKey<>(
"wdm.geckoDriverMirrorUrl", URL.class);
ConfigKey<URL> firefoxDriverGoodVersionsUrl = new ConfigKey<>(
"wdm.geckoDriverGoodVersionsUrl", URL.class);

ConfigKey<String> iExplorerDriverVersion = new ConfigKey<>(
"wdm.iExplorerDriverVersion", String.class);
Expand Down Expand Up @@ -913,6 +915,15 @@ public Config setFirefoxDriverMirrorUrl(URL value) {
return this;
}

public URL getFirefoxDriverGoodVersionsUrl() {
return resolve(firefoxDriverGoodVersionsUrl);
}

public Config setFirefoxDriverGoodVersionsUrl(URL value) {
this.firefoxDriverGoodVersionsUrl.setValue(value);
return this;
}

public String getIExplorerDriverVersion() {
return resolve(iExplorerDriverVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static io.github.bonigarcia.wdm.config.DriverManagerType.FIREFOX;
import static java.util.Optional.empty;
import static java.util.stream.Collectors.toList;

import java.io.File;
import java.io.IOException;
Expand All @@ -30,6 +31,9 @@

import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.DriverManagerType;
import io.github.bonigarcia.wdm.online.GeckodriverSupport;
import io.github.bonigarcia.wdm.online.GeckodriverSupport.GeckodriverRelease;
import io.github.bonigarcia.wdm.online.Parser;
import io.github.bonigarcia.wdm.versions.Shell;

/**
Expand Down Expand Up @@ -103,6 +107,16 @@ protected List<URL> getDriverUrls(String driverVersion) throws IOException {
}
}

@Override
protected Optional<String> getLatestDriverVersionFromRepository() {
if (config().isUseBetaVersions()
|| config().isAvoidReadReleaseFromRepository()) {
return empty();
} else {
return getDriverVersionFromRepository(empty());
}
}

@Override
protected String getCurrentVersion(URL url) {
int firstDash = url.getFile().indexOf(DASH);
Expand All @@ -118,6 +132,28 @@ protected String getCurrentVersion(URL url) {
@Override
protected Optional<String> getDriverVersionFromRepository(
Optional<String> driverVersion) {
URL firefoxDriverUrl = config.getFirefoxDriverGoodVersionsUrl();
try {
log.debug("Reading {} to discover geckodriver version",
firefoxDriverUrl);
GeckodriverSupport versions = Parser.parseJson(httpClient,
firefoxDriverUrl.toString(), GeckodriverSupport.class);
int majorBrowserVersion = Integer.parseInt(resolvedBrowserVersion);
List<GeckodriverRelease> fileteredList = versions.geckodriverReleases
.stream()
.filter(r -> majorBrowserVersion >= r.minFirefoxVersion
&& (r.maxFirefoxVersion == null
|| (r.maxFirefoxVersion != null
&& majorBrowserVersion <= r.maxFirefoxVersion)))
.collect(toList());

if (!fileteredList.isEmpty()) {
return Optional.of(fileteredList.get(0).geckodriverVersion);
}
} catch (Exception e) {
log.warn("Exception getting geckodriver version from {}",
firefoxDriverUrl, e);
}
return empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* (C) Copyright 2024 Boni Garcia (https://bonigarcia.github.io/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.github.bonigarcia.wdm.online;

import java.util.List;

import com.google.gson.annotations.SerializedName;

/**
* POJO to parse geckodriver-support.json
* (https://raw.githubusercontent.com/SeleniumHQ/selenium/trunk/common/geckodriver/geckodriver-support.json).
*
* @author Boni Garcia
* @since 5.7.0
*/
public class GeckodriverSupport {

@SerializedName("geckodriver-releases")
public List<GeckodriverRelease> geckodriverReleases;

public class GeckodriverRelease {
@SerializedName("geckodriver-version")
public String geckodriverVersion;

@SerializedName("min-firefox-version")
public Integer minFirefoxVersion;

@SerializedName("max-firefox-version")
public Integer maxFirefoxVersion;
}

}
1 change: 1 addition & 0 deletions src/main/resources/webdrivermanager.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ wdm.chromeLastGoodVersionsUrl=https://googlechromelabs.github.io/chrome-for-test
wdm.geckoDriverUrl=https://raw.githubusercontent.com/bonigarcia/webdrivermanager/master/docs/mirror/geckodriver
wdm.geckoDriverMirrorUrl=https://registry.npmmirror.com/-/binary/geckodriver/
wdm.geckoDriverExport=webdriver.gecko.driver
wdm.geckoDriverGoodVersionsUrl=https://raw.githubusercontent.com/SeleniumHQ/selenium/trunk/common/geckodriver/geckodriver-support.json

wdm.operaDriverUrl=https://raw.githubusercontent.com/bonigarcia/webdrivermanager/master/docs/mirror/operadriver
wdm.operaDriverMirrorUrl=https://registry.npmmirror.com/-/binary/operadriver/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2021 Boni Garcia (https://bonigarcia.github.io/)
* (C) Copyright 2024 Boni Garcia (https://bonigarcia.github.io/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,24 +25,22 @@
import org.junit.jupiter.params.provider.MethodSource;

import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.OperatingSystem;

class Firefox90Test {
class FirefoxMajorBrowserVersionTest {

@ParameterizedTest
@MethodSource("data")
void test(OperatingSystem os, String driverVersion) {
void test(String browserVersion, String driverVersion) {
WebDriverManager wdm = WebDriverManager.firefoxdriver()
.operatingSystem(os).browserVersion("90").avoidResolutionCache()
.useLocalVersionsPropertiesFirst();
.browserVersion(browserVersion).avoidResolutionCache();
wdm.setup();
assertThat(wdm.getDownloadedDriverVersion()).isEqualTo(driverVersion);
}

static Stream<Arguments> data() {
return Stream.of(Arguments.of(OperatingSystem.MAC, "0.29.0"),
Arguments.of(OperatingSystem.LINUX, "0.29.1"),
Arguments.of(OperatingSystem.WIN, "0.29.0"));
return Stream.of(Arguments.of("101", "0.31.0"),
Arguments.of("91", "0.31.0"), Arguments.of("90", "0.30.0"),
Arguments.of("62", "0.29.1"), Arguments.of("53", "0.18.0"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package io.github.bonigarcia.wdm.test.firefox;

import static org.junit.jupiter.api.condition.OS.LINUX;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.openqa.selenium.firefox.FirefoxDriver;

import io.github.bonigarcia.wdm.test.base.VersionTestParent;
Expand All @@ -30,7 +27,6 @@
* @author Boni Garcia
* @since 1.5.0
*/
@EnabledOnOs(LINUX)
class FirefoxVersionTest extends VersionTestParent {

@BeforeEach
Expand Down

0 comments on commit c2880ad

Please sign in to comment.