diff --git a/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java b/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java index e0a75e4b1..3a5ed3b45 100644 --- a/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java +++ b/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java @@ -20,6 +20,7 @@ import static io.github.bonigarcia.wdm.config.Architecture.X32; import static io.github.bonigarcia.wdm.config.Architecture.X64; import static io.github.bonigarcia.wdm.config.Config.isNullOrEmpty; +import static io.github.bonigarcia.wdm.config.DriverManagerType.CHROME; import static io.github.bonigarcia.wdm.config.DriverManagerType.CHROMIUM; import static io.github.bonigarcia.wdm.config.DriverManagerType.EDGE; import static io.github.bonigarcia.wdm.config.DriverManagerType.FIREFOX; @@ -1373,6 +1374,12 @@ protected boolean isUseMirror() { return getMirrorUrl().isPresent() && config().isUseMirror(); } + protected boolean isChrome() { + DriverManagerType managerType = getDriverManagerType(); + return managerType != null + && (managerType == CHROME || managerType == CHROMIUM); + } + protected String getCurrentVersion(URL url) { String urlFile = url.getFile(); if (isUseMirror()) { @@ -1439,10 +1446,13 @@ protected UrlHandler createUrlHandler(String driverVersion) boolean getLatest = isUnknown(driverVersion); boolean continueSearchingVersion; + boolean isCfT = isChrome() && VersionDetector.isCfT(driverVersion); do { // Filter by driver name - urlHandler.filterByDriverName(shortDriverName); + if (!isCfT) { + urlHandler.filterByDriverName(shortDriverName); + } // Filter for latest or concrete driver version if (getLatest) { @@ -1495,11 +1505,23 @@ protected UrlHandler createUrlHandler(String driverVersion) candidateUrls = urlHandler.getCandidateUrls(); } } while (continueSearchingVersion); + + if (isCfT) { + List driversFromMirror = getMirrorUrls( + urlHandler.getCandidateUrl(), ""); + urlHandler.setCandidateUrls(driversFromMirror); + urlHandler.filterByDriverName(shortDriverName); + } + return urlHandler; } protected List getDriversFromMirror(URL driverUrl, String driverVersion) throws IOException { + if (isChrome() && VersionDetector.isCfT(driverVersion)) { + driverUrl = config().getChromeDriverCfTMirrorUrl(); + config().setChromeDriverCfTMirrorUrl(driverUrl); + } List urls = new ArrayList<>(); if (isNullOrEmpty(driverVersion)) { List mirrorUrls = getMirrorUrls(driverUrl, ""); diff --git a/src/main/java/io/github/bonigarcia/wdm/config/Config.java b/src/main/java/io/github/bonigarcia/wdm/config/Config.java index c6171d0d1..07deda610 100644 --- a/src/main/java/io/github/bonigarcia/wdm/config/Config.java +++ b/src/main/java/io/github/bonigarcia/wdm/config/Config.java @@ -121,6 +121,8 @@ public class Config { URL.class); ConfigKey chromeDriverMirrorUrl = new ConfigKey<>( "wdm.chromeDriverMirrorUrl", URL.class); + ConfigKey chromeDriverCfTMirrorUrl = new ConfigKey<>( + "wdm.chromeDriverCfTMirrorUrl", URL.class); ConfigKey chromeDownloadUrlPattern = new ConfigKey<>( "wdm.chromeDownloadUrlPattern", String.class); ConfigKey chromeGoodVersionsUrl = new ConfigKey<>( @@ -765,6 +767,15 @@ public Config setChromeDriverMirrorUrl(URL value) { return this; } + public URL getChromeDriverCfTMirrorUrl() { + return resolve(chromeDriverCfTMirrorUrl); + } + + public Config setChromeDriverCfTMirrorUrl(URL value) { + this.chromeDriverCfTMirrorUrl.setValue(value); + return this; + } + public String getChromeDownloadUrlPattern() { return resolve(chromeDownloadUrlPattern); } diff --git a/src/main/java/io/github/bonigarcia/wdm/managers/ChromeDriverManager.java b/src/main/java/io/github/bonigarcia/wdm/managers/ChromeDriverManager.java index 12cfa3790..de3a0c0ff 100644 --- a/src/main/java/io/github/bonigarcia/wdm/managers/ChromeDriverManager.java +++ b/src/main/java/io/github/bonigarcia/wdm/managers/ChromeDriverManager.java @@ -56,8 +56,6 @@ */ public class ChromeDriverManager extends WebDriverManager { - public static final int MIN_CHROMEDRIVER_IN_CFT = 115; - private static final String CHROMEDRIVER_DOWNLOAD_OLD_PATTERN = "https://chromedriver.storage.googleapis.com/%s/chromedriver_%s%s.zip"; @Override @@ -173,9 +171,7 @@ Optional buildUrl(String driverVersion, Config config) { String builtUrl = String.format(downloadUrlPattern, driverVersion, label, label); - if (!isNullOrEmpty(driverVersion) - && Integer.parseInt(VersionDetector.getMajorVersion( - driverVersion)) < MIN_CHROMEDRIVER_IN_CFT) { + if (!VersionDetector.isCfT(driverVersion)) { archLabel = os.isWin() ? "32" : "64"; builtUrl = String.format(CHROMEDRIVER_DOWNLOAD_OLD_PATTERN, driverVersion, os.getName(), archLabel); diff --git a/src/main/java/io/github/bonigarcia/wdm/online/Downloader.java b/src/main/java/io/github/bonigarcia/wdm/online/Downloader.java index 0f8752370..4de1348e4 100644 --- a/src/main/java/io/github/bonigarcia/wdm/online/Downloader.java +++ b/src/main/java/io/github/bonigarcia/wdm/online/Downloader.java @@ -19,7 +19,6 @@ import static io.github.bonigarcia.wdm.config.Architecture.ARM64; import static io.github.bonigarcia.wdm.config.DriverManagerType.CHROME; import static io.github.bonigarcia.wdm.config.DriverManagerType.CHROMIUM; -import static io.github.bonigarcia.wdm.managers.ChromeDriverManager.MIN_CHROMEDRIVER_IN_CFT; import static java.io.File.separator; import static java.lang.invoke.MethodHandles.lookup; import static java.nio.file.Files.createTempDirectory; @@ -101,10 +100,7 @@ public File getTarget(String driverVersion, String driverName, OperatingSystem os = config.getOperatingSystem(); String architecture = config.getArchitecture().toString() .toLowerCase(ROOT); - int majorDriverVersion = Integer - .parseInt(VersionDetector.getMajorVersion(driverVersion)); - - if (os.isWin() && majorDriverVersion < MIN_CHROMEDRIVER_IN_CFT + if (os.isWin() && !VersionDetector.isCfT(driverVersion) && (driverManagerType == CHROME || driverManagerType == CHROMIUM)) { log.trace( diff --git a/src/main/java/io/github/bonigarcia/wdm/online/UrlHandler.java b/src/main/java/io/github/bonigarcia/wdm/online/UrlHandler.java index fce29ad5d..407553524 100644 --- a/src/main/java/io/github/bonigarcia/wdm/online/UrlHandler.java +++ b/src/main/java/io/github/bonigarcia/wdm/online/UrlHandler.java @@ -290,4 +290,8 @@ public URL getCandidateUrl() { return candidateUrls.iterator().next(); } + public void setCandidateUrls(List candidateUrls) { + this.candidateUrls = candidateUrls; + } + } diff --git a/src/main/java/io/github/bonigarcia/wdm/versions/VersionDetector.java b/src/main/java/io/github/bonigarcia/wdm/versions/VersionDetector.java index 1b9f71148..d3d836516 100644 --- a/src/main/java/io/github/bonigarcia/wdm/versions/VersionDetector.java +++ b/src/main/java/io/github/bonigarcia/wdm/versions/VersionDetector.java @@ -18,7 +18,6 @@ import static io.github.bonigarcia.wdm.WebDriverManager.loadXML; import static io.github.bonigarcia.wdm.config.Config.isNullOrEmpty; -import static io.github.bonigarcia.wdm.managers.ChromeDriverManager.MIN_CHROMEDRIVER_IN_CFT; import static io.github.bonigarcia.wdm.versions.Shell.runAndWait; import static java.lang.invoke.MethodHandles.lookup; import static java.nio.charset.StandardCharsets.UTF_8; @@ -74,6 +73,7 @@ public class VersionDetector { static final String COMMANDS_PROPERTIES = "commands.properties"; static final String FILE_PROTOCOL = "file"; static final String CFT_URL = "https://googlechromelabs.github.io/chrome-for-testing/"; + static final int MIN_CHROMEDRIVER_IN_CFT = 115; final Logger log = getLogger(lookup().lookupClass()); @@ -102,8 +102,7 @@ public Optional getDriverVersionFromRepository( if (driverName.equalsIgnoreCase("chromedriver")) { String cftUrl = null; try { - if (driverVersion.isPresent() && Integer.parseInt( - driverVersion.get()) >= MIN_CHROMEDRIVER_IN_CFT) { + if (driverVersion.isPresent() && isCfT(driverVersion.get())) { // Parse JSON using GoodVersions cftUrl = config.getChromeGoodVersionsUrl(); @@ -400,6 +399,11 @@ public static String getMajorVersion(String version) { } } + public static boolean isCfT(String driverVersion) { + return isNullOrEmpty(driverVersion) || Integer.parseInt(VersionDetector + .getMajorVersion(driverVersion)) >= MIN_CHROMEDRIVER_IN_CFT; + } + protected File findFileLocation(String filename) { // Alternative #1: in System32 folder File system32Folder = new File(System.getenv("SystemRoot"), "System32"); diff --git a/src/main/resources/webdrivermanager.properties b/src/main/resources/webdrivermanager.properties index f1ae0e173..868843ef7 100644 --- a/src/main/resources/webdrivermanager.properties +++ b/src/main/resources/webdrivermanager.properties @@ -24,6 +24,7 @@ wdm.serverTimeoutSec=60 wdm.chromeDriverUrl=https://chromedriver.storage.googleapis.com/ wdm.chromeDriverMirrorUrl=https://registry.npmmirror.com/-/binary/chromedriver/ +wdm.chromeDriverCfTMirrorUrl=https://registry.npmmirror.com/-/binary/chrome-for-testing/ wdm.chromeDriverExport=webdriver.chrome.driver wdm.chromeDownloadUrlPattern=https://storage.googleapis.com/chrome-for-testing-public/%s/%s/chromedriver-%s.zip wdm.chromeGoodVersionsUrl=https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json diff --git a/src/test/java/io/github/bonigarcia/wdm/test/mirror/MirrorTest.java b/src/test/java/io/github/bonigarcia/wdm/test/mirror/MirrorTest.java index e08e08355..dce8ccefa 100644 --- a/src/test/java/io/github/bonigarcia/wdm/test/mirror/MirrorTest.java +++ b/src/test/java/io/github/bonigarcia/wdm/test/mirror/MirrorTest.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.File; -import java.net.URL; import java.util.List; import org.junit.jupiter.api.Disabled; @@ -39,20 +38,26 @@ class MirrorTest { @Test - void testMirrorChrome() throws Exception { + void testMirrorChrome() { WebDriverManager wdm = WebDriverManager.chromedriver() - .browserVersion("100").avoidBrowserDetection() - .avoidResolutionCache().clearResolutionCache().useMirror() + .clearResolutionCache().useMirror().forceDownload(); + wdm.setup(); + File driver = new File(wdm.getDownloadedDriverPath()); + assertThat(driver).exists(); + } + + @Test + void testOldMirrorChrome() { + WebDriverManager wdm = WebDriverManager.chromedriver() + .browserVersion("100").clearResolutionCache().useMirror() .forceDownload(); - wdm.config().setChromeDriverMirrorUrl(new URL( - "https://registry.npmmirror.com/-/binary/chromedriver/")); wdm.setup(); File driver = new File(wdm.getDownloadedDriverPath()); assertThat(driver).exists(); } @Test - void testMirrorFirefox() throws Exception { + void testMirrorFirefox() { WebDriverManager wdm = WebDriverManager.firefoxdriver().useMirror() .forceDownload(); wdm.setup(); @@ -61,7 +66,7 @@ void testMirrorFirefox() throws Exception { } @Test - void testMirrorOpera() throws Exception { + void testMirrorOpera() { WebDriverManager wdm = WebDriverManager.operadriver().useMirror() .browserVersion("97").forceDownload(); wdm.setup();