Skip to content

Commit

Permalink
Add android options to chromium options.
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Sep 30, 2021
1 parent 73807b6 commit b95aa5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
40 changes: 40 additions & 0 deletions java/src/org/openqa/selenium/chromium/ChromiumOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class ChromiumOptions<T extends ChromiumOptions<?>> extends AbstractDrive
private final List<File> extensionFiles = new ArrayList<>();
private final List<String> extensions = new ArrayList<>();
private final Map<String, Object> experimentalOptions = new HashMap<>();
private Map<String, Object> androidOptions = new HashMap<>();

private final String capabilityName;

Expand Down Expand Up @@ -193,6 +194,43 @@ public T setHeadless(boolean headless) {
return (T) this;
}

public T setAndroidPackage(String androidPackage) {
Require.nonNull("Android package", androidPackage);
return setAndroidCapability("androidPackage", androidPackage);
}

public T setAndroidActivity(String activity) {
Require.nonNull("Android activity", activity);
return setAndroidCapability("androidActivity", activity);
}

public T setAndroidDeviceSerialNumber(String serial) {
Require.nonNull("Android device serial number", serial);
return setAndroidCapability("androidDeviceSerial", serial);
}

public T setUseRunningAndroidApp(boolean useIt) {
return setAndroidCapability("androidUseRunningApp", useIt);
}

/**
* Process name of the Activity hosting the WebView (as given by ps).
* If not set, the process name is assumed to be the same as androidPackage.
*/
public T setAndroidProcess(String processName) {
Require.nonNull("Android process name", processName);
return setAndroidCapability("androidProcess", processName);
}

private T setAndroidCapability(String name, Object value) {
Require.nonNull("Name", name);
Require.nonNull("Value", value);
Map<String, Object> newOptions = new TreeMap<>(androidOptions);
newOptions.put(name, value);
androidOptions = Collections.unmodifiableMap(newOptions);
return (T) this;
}

@Override
protected Set<String> getExtraCapabilityNames() {
return Collections.singleton(capabilityName);
Expand Down Expand Up @@ -228,6 +266,8 @@ protected Object getExtraCapability(String capabilityName) {
extensions.stream()
).collect(toList())));

options.putAll(androidOptions);

return unmodifiableMap(options);
}

Expand Down
12 changes: 12 additions & 0 deletions java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,16 @@ public void isW3CSafe() {

assertThat(seen).isEmpty();
}

@Test
public void shouldBeAbleToSetAnAndroidOption() {
Map<String, Object> converted = new ChromeOptions()
.setAndroidActivity("com.cheese.nom")
.asMap();

assertThat(converted)
.extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP)
.extractingByKey("androidActivity")
.isEqualTo("com.cheese.nom");
}
}

0 comments on commit b95aa5a

Please sign in to comment.