Skip to content

Commit

Permalink
Capabilities handler accepts also boolean capabilities (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Oct 26, 2023
1 parent 2771cb0 commit bf88832
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/main/java/io/github/bonigarcia/seljup/CapabilitiesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Optional<Class<? extends Capabilities>> getOptionsClass() {
&& browserType.get() == BrowserType.FIREFOX)) {
return Optional.of(FirefoxOptions.class);
} else if (isOpera || (browserType.isPresent()
&& browserType.get() == BrowserType.OPERA)) {
&& browserType.get() == BrowserType.OPERA)) {
return Optional.of(ChromeOptions.class);
} else if (type == EdgeDriver.class || (browserType.isPresent()
&& browserType.get() == BrowserType.EDGE)) {
Expand Down Expand Up @@ -178,13 +178,21 @@ private void handleCapabilities(Class<? extends Capabilities> optionsClass,
&& browser.get().getCapabilities() != null) {
Method setCapabilityMethod = optionsClass
.getMethod("setCapability", String.class, String.class);

Method setCapabilityBooleanMethod = optionsClass.getMethod(
"setCapability", String.class, boolean.class);
@SuppressWarnings("unchecked")
Set<Entry<String, String>> caps = ((LinkedTreeMap<String, String>) browser
Set<Entry<String, Object>> caps = ((LinkedTreeMap<String, Object>) browser
.get().getCapabilities()).entrySet();
for (Entry<String, String> entry : caps) {
setCapabilityMethod.invoke(options, entry.getKey(),
entry.getValue());

for (Entry<String, Object> entry : caps) {
Object value = entry.getValue();
if (value.getClass().equals(Boolean.class)) {
setCapabilityBooleanMethod.invoke(options,
entry.getKey(), entry.getValue());
} else {
setCapabilityMethod.invoke(options, entry.getKey(),
entry.getValue());
}
}
}
} catch (Exception e) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/browsers-caps.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"capabilities" : {
"custom:cap-1": "custom-value-1",
"custom:cap-2": "custom-value-2"
"custom:cap-2": "custom-value-2",
"custom:cap-3": true
}
}
],
Expand Down

0 comments on commit bf88832

Please sign in to comment.