Skip to content

Commit

Permalink
Avoid people from using selenium 3.7.1 with grid extras 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
smccarthy-godaddy committed Nov 25, 2017
1 parent 4772fa4 commit 350f114
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Capability> capabilities, String hubHost,
String hubPort, Config defaultConfig, String nodePort) {
GridNode node = new GridNode(defaultConfig.getWebdriver().getVersion().startsWith("3."));
Expand Down Expand Up @@ -425,7 +446,7 @@ private static List<Capability> 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()) {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
}

0 comments on commit 350f114

Please sign in to comment.