Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added usage of chromeoptions.binary #546

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,23 @@ private ChromeOptions transferChromeOptionsFromSystemProperties(ChromeOptions cu
for (String key : System.getProperties().stringPropertyNames()) {
if (key.startsWith(prefix)) {
String capability = key.substring(prefix.length());
if (capability == null) {
continue;
}
String value = System.getProperties().getProperty(key);
if (capability.equals("args")) {
List<String> args = Arrays.asList(value.split(","));
currentChromeOptions.addArguments(args);
} else {
log.warning(capability + "is ignored." +
"Only so-called arguments (chromeoptions.args=<values comma separated>) " +
"are supported for the chromeoptions at the moment");
switch (capability) {
case "args":
List<String> args = Arrays.asList(value.split(","));
currentChromeOptions.addArguments(args);
break;
case "binary":
currentChromeOptions.setBinary(value);
break;
default:
log.warning(capability + "is ignored." +
"Only so-called arguments (chromeoptions.args=<values comma separated>) " +
"are supported for the chromeoptions at the moment");
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -114,6 +115,20 @@ public void transferChromeOptionArgumentsFromSystemPropsToDriver() throws IOExce
assertThat(arrayOfArguments, containsString("xcvcd=123"));
}

@Test
public void transferChromeOptionBinaryFromSystemPropsToDriver() throws IOException {
System.setProperty("chromeoptions.binary", "/tmp/chrome");
String binary = factory.createChromeOptions().toJson().getAsJsonObject().getAsJsonPrimitive("binary").getAsString();
assertThat(binary, is("/tmp/chrome"));
}

@Test
public void ignoreIllegalChromeOptionsFromSystemPropsToDriver() throws IOException {
System.setProperty("chromeoptions.", "illegal chrome options");
String options = factory.createChromeOptions().toJson().toString();
assertThat(options, not(containsString("illegal chrome options")));
}

@After
public void tearDown() {
System.clearProperty("capabilities.some.cap");
Expand Down