Skip to content

Commit

Permalink
[java] Allow arguments to be passed in Node flag "driver-configuration"
Browse files Browse the repository at this point in the history
Fixed #11341
  • Loading branch information
pujagani committed Dec 5, 2022
1 parent 77f0cfa commit 027a5b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ private void addDriverConfigs(
int toIndex = (i + 1) >= configIndexes.length ? drivers.size() : configIndexes[i + 1];
Map<String, String> configMap = new HashMap<>();
drivers.subList(fromIndex, toIndex)
.forEach(keyValue -> configMap.put(keyValue.split("=")[0], keyValue.split("=")[1]));
.forEach(keyValue -> {
String [] values = keyValue.split("=", 2);
configMap.put(values[0], values[1]);
});
driversMap.add(configMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import static java.util.Collections.emptySet;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand Down Expand Up @@ -366,6 +368,43 @@ void driversCanBeConfiguredWithASpecificWebDriverBinary() {
geckoDriverLocation.equals(capabilities.getCapability("se:webDriverExecutable")));
}

@Test
void driversCanBeConfiguredWithASpecificArguments() {
String chLocation = "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta";
String chromeDriverLocation = "/path/to/chromedriver_beta/chromedriver";
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(chLocation);
chromeOptions.addArguments("--homepage=https://www.selenium.dev");

StringBuilder chromeCaps = new StringBuilder();
new Json().newOutput(chromeCaps).setPrettyPrint(false).write(chromeOptions);

String[] rawConfig = new String[]{
"[node]",
"detect-drivers = false",
"[[node.driver-configuration]]",
"display-name = \"Chrome Beta\"",
String.format("webdriver-executable = '%s'", chromeDriverLocation),
String.format("stereotype = \"%s\"", chromeCaps.toString().replace("\"", "\\\""))
};
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));

List<Capabilities> reported = new ArrayList<>();
new NodeOptions(config).getSessionFactories(capabilities -> {
reported.add(capabilities);
return Collections.singleton(HelperFactory.create(config, capabilities));
});

assertThat(reported).is(supporting("chrome"));
assertThat(reported)
.filteredOn(capabilities -> capabilities.asMap().containsKey(ChromeOptions.CAPABILITY));

assertThat(reported.get(0).asMap()).asInstanceOf(MAP)
.extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP)
.extractingByKey("args").asInstanceOf(LIST)
.containsExactly("--homepage=https://www.selenium.dev");
}

@Test
void driversConfigNeedsStereotypeField() {
String[] rawConfig = new String[]{
Expand Down

0 comments on commit 027a5b5

Please sign in to comment.