Skip to content

Commit f7a4c21

Browse files
committed
[grid] Allowing service config via CLI
When the relay feature was added, we forgot to add this CLI option. Fixes #10115
1 parent 2f93dee commit f7a4c21

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

‎java/src/org/openqa/selenium/grid/node/relay/RelayFlags.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,57 @@
2626

2727
import org.openqa.selenium.grid.config.ConfigValue;
2828
import org.openqa.selenium.grid.config.HasRoles;
29+
import org.openqa.selenium.grid.config.NonSplittingSplitter;
2930
import org.openqa.selenium.grid.config.Role;
3031

3132
import java.util.Collections;
33+
import java.util.List;
3234
import java.util.Set;
3335

3436
@SuppressWarnings("unused")
3537
@AutoService(HasRoles.class)
3638
public class RelayFlags implements HasRoles {
3739

40+
@Parameter(
41+
names = {"--service-configuration"},
42+
description = "Configuration for the service where calls will be relayed to. " +
43+
"It is recommended to provide this type of configuration through a toml config " +
44+
"file to improve readability. Command line example: " +
45+
"--service-configuration max-sessions=2 " +
46+
"stereotype='{\"browserName\": \"safari\", \"platformName\": \"iOS\", " +
47+
"\"appium:platformVersion\": \"14.5\"}}'",
48+
arity = 4,
49+
variableArity = true,
50+
splitter = NonSplittingSplitter.class)
51+
@ConfigValue(
52+
section = RELAY_SECTION,
53+
name = "configs",
54+
prefixed = true,
55+
example = "\n" +
56+
"max-sessions = 2\n" +
57+
"stereotype = \"{\"browserName\": \"safari\", \"platformName\": \"iOS\", " +
58+
"\"appium:platformVersion\": \"14.5\" }}\"")
59+
public List<String> driverConfiguration;
60+
3861
@Parameter(
3962
names = {"--service-url"},
4063
description = "URL for connecting to the service that supports WebDriver commands, "
4164
+ "like an Appium server or a cloud service."
4265
)
4366
@ConfigValue(section = RELAY_SECTION, name = "url", example = "http://localhost:4723")
4467
private String serviceUrl;
45-
4668
@Parameter(
4769
names = {"--service-host"},
4870
description = "Host name where the service that supports WebDriver commands is running"
4971
)
5072
@ConfigValue(section = RELAY_SECTION, name = "host", example = "\"localhost\"")
5173
private String serviceHost;
52-
5374
@Parameter(
5475
names = {"--service-port"},
5576
description = "Port where the service that supports WebDriver commands is running"
5677
)
5778
@ConfigValue(section = RELAY_SECTION, name = "port", example = "4723")
5879
private Integer servicePort;
59-
6080
@Parameter(
6181
names = {"--service-status-endpoint"},
6282
description = "Endpoint to query the WebDriver service status, an HTTP 200 response "

‎java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ public Map<Capabilities, Collection<SessionFactory>> getSessionFactories(
124124
for (int i = 0; i < allConfigs.size(); i++) {
125125
int maxSessions;
126126
try {
127-
maxSessions = Integer.parseInt(allConfigs.get(i));
127+
maxSessions = Integer.parseInt(extractConfiguredValue(allConfigs.get(i)));
128128
} catch (NumberFormatException e) {
129129
throw new ConfigException("Unable parse value as number. " + allConfigs.get(i));
130130
}
131131
i++;
132132
if (i == allConfigs.size()) {
133133
throw new ConfigException("Unable to find stereotype config. " + allConfigs);
134134
}
135-
Capabilities stereotype = JSON.toType(allConfigs.get(i), Capabilities.class);
135+
Capabilities stereotype = JSON.toType(
136+
extractConfiguredValue(allConfigs.get(i)),
137+
Capabilities.class);
136138
parsedConfigs.put(maxSessions, stereotype);
137139
}
138140

@@ -153,4 +155,11 @@ public Map<Capabilities, Collection<SessionFactory>> getSessionFactories(
153155
return factories.build().asMap();
154156
}
155157

158+
private String extractConfiguredValue(String keyValue) {
159+
if (keyValue.contains("=")) {
160+
return keyValue.substring(keyValue.indexOf("=") + 1);
161+
}
162+
return keyValue;
163+
}
164+
156165
}

0 commit comments

Comments
 (0)