diff --git a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/config/FirstTimeRunConfig.java b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/config/FirstTimeRunConfig.java index 004b7f50..678ae490 100644 --- a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/config/FirstTimeRunConfig.java +++ b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/config/FirstTimeRunConfig.java @@ -41,6 +41,7 @@ import com.google.gson.JsonPrimitive; import com.groupon.seleniumgridextras.ExecuteCommand; import com.groupon.seleniumgridextras.OS; +import com.groupon.seleniumgridextras.Version; import com.groupon.seleniumgridextras.browser.BrowserVersionDetector; import com.groupon.seleniumgridextras.config.capabilities.Capability; import com.groupon.seleniumgridextras.config.remote.ConfigPusher; @@ -52,6 +53,7 @@ import com.groupon.seleniumgridextras.utilities.FileIOUtility; import com.groupon.seleniumgridextras.utilities.ValueConverter; import com.groupon.seleniumgridextras.utilities.json.JsonCodec; +import com.groupon.seleniumgridextras.utilities.VersionCompare; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -244,7 +246,7 @@ private static void setRebootAfterSessionLimit(Config defaultConfig) { } } - + private static void setUnregisterNodeDuringReboot(Config defaultConfig) { if (!defaultConfig.getAutoStartHub()) { // If this is a HUB, we never want to restart it @@ -263,6 +265,12 @@ private static void setUnregisterNodeDuringReboot(Config defaultConfig) { } private static void setDriverAutoUpdater(Config defaultConfig) { + String gridExtrasVersion = Version.getSanitizedVersion(); + if (gridExtrasVersion.startsWith("1.")) { + System.out.println("WARNING: Selenium 3.7.0 is the latest compatible version with Selenium-Grid-Extras 1.x. Upgrade to Selenium-Grid-Extras 2.x if you would like to use the latest webdriver."); + } else if (gridExtrasVersion.startsWith("2.")) { + System.out.println("WARNING: Selenium 3.7.1 is the oldest compatible version with Selenium-Grid-Extras 2.x. Downgrade to Selenium-Grid-Extras 1.x if you would like to use an older version of webdriver."); + } String answer = askQuestion( @@ -293,6 +301,19 @@ private static void setDriverAutoUpdater(Config defaultConfig) { } defaultConfig.getChromeDriver().setVersion(versionOfChrome); defaultConfig.getGeckoDriver().setVersion(versionOfGecko); + + if(gridExtrasVersion.startsWith("1.")) { + if(VersionCompare.versionCompare(versionOfWebDriver, "3.7.1") >= 0) { + System.out.println("WARNING: Selenium " + versionOfWebDriver + " is not compatible with this verison of Selenium-Grid-Extras. Changing your selection to 3.7.0. Please upgrade to Selenium-Grid-Extras 2.x to use selenium " + versionOfWebDriver); + versionOfWebDriver = "3.7.0"; + } + } else if(gridExtrasVersion.startsWith("2.")) { + if(VersionCompare.versionCompare(versionOfWebDriver, "3.7.1") < 0) { + System.out.println("WARNING: Selenium " + versionOfWebDriver + " is not compatible with this verison of Selenium-Grid-Extras. Changing your selection to 3.7.1. Please downgrade to Selenium-Grid-Extras 1.x to use selenium " + versionOfWebDriver); + versionOfWebDriver = "3.7.1"; + } + } + defaultConfig.getWebdriver().setVersion(versionOfWebDriver); String bitOfChromeDriver = JsonCodec.WebDriver.Downloader.BIT_32; @@ -334,7 +355,7 @@ private static void setDriverAutoUpdater(Config defaultConfig) { System.out.printf("Current IE Driver Version: %s (%s bit)\n", defaultConfig.getIEdriver().getVersion(), defaultConfig.getIEdriver().getBit()); } } - + private static void configureNodes(List capabilities, String hubHost, String hubPort, Config defaultConfig, String nodePort) { GridNode node = new GridNode(defaultConfig.getWebdriver().getVersion().startsWith("3.")); @@ -425,7 +446,7 @@ private static List getCapabilitiesFromUser(Config defaultConfig) { guessedPlatform); - /* If we can't detect the correct browser version, default to No for auto updating the + /* If we can't detect the correct browser version, default to No for auto updating the * browser version automatically on node startup */ String ableToAutoDetectBrowserVersions = "1"; for (Class currentCapabilityClass : Capability.getSupportedWebCapabilities().keySet()) { @@ -544,7 +565,7 @@ private static void setGridExtrasPort(Config defaultConfig) { String answer = askQuestion("What is the PORT for Selenium Grid Extras?", "3000"); - + defaultConfig.setGridExtrasPort(answer); } diff --git a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/AutoUpgradeDrivers.java b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/AutoUpgradeDrivers.java index cbfdfbc3..43b8b01a 100644 --- a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/AutoUpgradeDrivers.java +++ b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/AutoUpgradeDrivers.java @@ -7,6 +7,8 @@ import com.groupon.seleniumgridextras.config.RuntimeConfig; import com.groupon.seleniumgridextras.tasks.config.TaskDescriptions; import com.groupon.seleniumgridextras.utilities.json.JsonCodec; +import com.groupon.seleniumgridextras.Version; +import com.groupon.seleniumgridextras.utilities.VersionCompare; import org.apache.log4j.Logger; @@ -85,9 +87,25 @@ public JsonObject execute() { } if (updateWebDriver) { + String gridExtrasVersion = Version.getSanitizedVersion(); String newWebDriverVersion = RuntimeConfig.getReleaseManager().getWedriverLatestVersion().getPrettyPrintVersion("."); + if(gridExtrasVersion.startsWith("1.")) { + if(VersionCompare.versionCompare(newWebDriverVersion, "3.7.1") >= 0) { + String message = String.format("SeleniumGridExtras 2.X is not compatible with Selenium version 3.7.0 or less."); + logger.info(message); + getJsonResponse().addKeyValues(JsonCodec.OUT, message); + return getJsonResponse().getJson(); + } + } else if(gridExtrasVersion.startsWith("2.")) { + if(VersionCompare.versionCompare(newWebDriverVersion, "3.7.1") < 0) { + String message = String.format("SeleniumGridExtras 2.X is not compatible with Selenium version 3.7.0 or less."); + logger.info(message); + getJsonResponse().addKeyValues(JsonCodec.OUT, message); + return getJsonResponse().getJson(); + } + } logger.info("WebDriver JAR " + genericUpdate + " " + newWebDriverVersion); RuntimeConfig.getConfig().getWebdriver().setVersion(newWebDriverVersion); updateVersionFor(configHash, "webdriver", newWebDriverVersion); diff --git a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/UpgradeGridExtrasTask.java b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/UpgradeGridExtrasTask.java index bda23224..e81bc23d 100644 --- a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/UpgradeGridExtrasTask.java +++ b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/UpgradeGridExtrasTask.java @@ -9,6 +9,7 @@ import com.groupon.seleniumgridextras.tasks.config.TaskDescriptions; import com.groupon.seleniumgridextras.utilities.FileIOUtility; import com.groupon.seleniumgridextras.utilities.json.JsonCodec; +import com.groupon.seleniumgridextras.utilities.VersionCompare; import org.apache.log4j.Logger; import java.io.File; @@ -203,6 +204,24 @@ public JsonObject execute(String version) { getJsonResponse().addKeyValues(JsonCodec.GridExtras.NEW_VERSION, version); + String webdriverVersion = RuntimeConfig.getConfig().getWebdriver().getVersion(); + System.out.println("webdriverVersion : " + webdriverVersion); + System.out.println("Upgraded version of grid extras : " + version); + if (version.startsWith("1.")) { + if (VersionCompare.versionCompare(webdriverVersion, "3.7.1") >= 0) { + String message = String.format("SeleniumGridExtras 2.X is not compatible with Selenium version 3.7.0 or less."); + logger.info(message); + getJsonResponse().addKeyValues(JsonCodec.OUT, message); + return getJsonResponse().getJson(); + } + } else if (version.startsWith("2.")) { + if (VersionCompare.versionCompare(webdriverVersion, "3.7.1") < 0) { + String message = String.format("SeleniumGridExtras 2.X is not compatible with Selenium version 3.7.0 or less."); + logger.info(message); + getJsonResponse().addKeyValues(JsonCodec.OUT, message); + return getJsonResponse().getJson(); + } + } File destinationJar = new File(RuntimeConfig.getSeleniungGridExtrasHomePath(), String.format("SeleniumGridExtras-%s-SNAPSHOT-jar-with-dependencies.jar", version)); diff --git a/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/utilities/VersionCompare.java b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/utilities/VersionCompare.java new file mode 100644 index 00000000..0868e952 --- /dev/null +++ b/SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/utilities/VersionCompare.java @@ -0,0 +1,40 @@ +package com.groupon.seleniumgridextras.utilities; + +public class VersionCompare { + + /** + Return 1 if version1 is greater than version2 + Return 0 if version 1 is equal to version2 + Return -1 if version 1 is less than version2 + */ + public static int versionCompare(String version1, String version2) { + String[] version1Split = version1.split("\\."); + String[] version2Split = version2.split("\\."); + int major1 = (version1Split.length > 0) ? Integer.parseInt(version1Split[0]) : 0; + int minor1 = (version1Split.length > 1) ? Integer.parseInt(version1Split[1]) : 0; + int patch1 = (version1Split.length > 2) ? Integer.parseInt(version1Split[2]) : 0; + + int major2 = (version2Split.length > 0) ? Integer.parseInt(version2Split[0]) : 0; + int minor2 = (version2Split.length > 1) ? Integer.parseInt(version2Split[1]) : 0; + int patch2 = (version2Split.length > 2) ? Integer.parseInt(version2Split[2]) : 0; + if (major1 > major2) { + return 1; + } else if (major1 < major2) { + return -1; + } else { // Majors match + if (minor1 > minor2) { + return 1; + } else if (minor1 < minor2) { + return -1; + } else { + if (patch1 > patch2) { + return 1; + } else if (patch1 < patch2) { + return -1; + } else { + return 0; + } + } + } + } +}