[grid] Detecting platform by default for Node
Fixes
import com.google.common.collect.Multimap;
import org.openqa.selenium.Capabilities;
+import org.openqa.selenium.ImmutableCapabilities;
+import org.openqa.selenium.Platform;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverInfo;
private static final Logger LOG = Logger.getLogger(NodeOptions.class.getName());
private static final Json JSON = new Json();
private static final String DEFAULT_IMPL = "org.openqa.selenium.grid.node.local.LocalNodeFactory";
+ private static final ImmutableCapabilities CURRENT_PLATFORM =
+ new ImmutableCapabilities("platformName", Platform.getCurrent());
+
private final Config config;
@@ -285,8 +290,11 @@ private void addDetectedDrivers(
.stream()
.peek(this::report)
.forEach(
- entry ->
- sessionFactories.putAll(entry.getKey().getCanonicalCapabilities(), entry.getValue()));
+ entry -> {
+ Capabilities capabilities = entry.getKey()
+ .getCanonicalCapabilities().merge(CURRENT_PLATFORM);
+ sessionFactories.putAll(capabilities, entry.getValue());
+ });
if (sessionFactories.build().size() == 0) {
String logMessage = "No drivers have been configured or have been found on PATH";
@@ -335,8 +343,11 @@ private void addSpecificDrivers(
.sorted(Comparator.comparing(entry -> entry.getKey().getDisplayName().toLowerCase()))
.peek(this::report)
.forEach(
- entry ->
- sessionFactories.putAll(entry.getKey().getCanonicalCapabilities(), entry.getValue()));
+ entry -> {
+ Capabilities capabilities = entry.getKey()
+ .getCanonicalCapabilities().merge(CURRENT_PLATFORM);
+ sessionFactories.putAll(capabilities, entry.getValue());
+ });
}
private Map<WebDriverInfo, Collection<SessionFactory>> discoverDrivers(
@@ -361,7 +372,7 @@ private void addSpecificDrivers(
Multimap<WebDriverInfo, SessionFactory> toReturn = HashMultimap.create();
infos.forEach(info -> {
- Capabilities caps = info.getCanonicalCapabilities();
+ Capabilities caps = info.getCanonicalCapabilities().merge(CURRENT_PLATFORM);
builders.stream()
.filter(builder -> builder.score(caps) > 0)
.forEach(builder -> {
@@ -419,7 +430,11 @@ private void report(Map.Entry<WebDriverInfo, Collection<SessionFactory>> entry)
StringBuilder caps = new StringBuilder();
try (JsonOutput out = JSON.newOutput(caps)) {
out.setPrettyPrint(false);
- out.write(entry.getKey().getCanonicalCapabilities());
+ Capabilities capabilities = entry.getKey().getCanonicalCapabilities();
+ if (capabilities.getPlatformName() == null) {
+ capabilities = capabilities.merge(CURRENT_PLATFORM);
+ }
+ out.write(capabilities);
}
LOG.info(String.format(
