Skip to content

Commit

Permalink
[java] Merge android specific parameters in chrome options (#14217)
Browse files Browse the repository at this point in the history
* added androidOptions in merge method

* applied suggestions

* applying format.sh

* import assertEquals

* fix for importi Optional

---------

Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
  • Loading branch information
iampopovich and diemol authored Jul 12, 2024
1 parent 9aa1a7f commit 4a17ec3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
19 changes: 7 additions & 12 deletions java/src/org/openqa/selenium/chromium/ChromiumOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.*;
import java.util.stream.Stream;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.SessionNotCreatedException;
Expand Down Expand Up @@ -320,10 +312,13 @@ protected void mergeInPlace(Capabilities capabilities) {
}
addExtensions(options.extensionFiles);
addEncodedExtensions(options.extensions);
if (options.binary != null) {
setBinary(options.binary);
}

Optional.ofNullable(options.binary).ifPresent(this::setBinary);

options.experimentalOptions.forEach(this::setExperimentalOption);

Optional.ofNullable(options.androidOptions)
.ifPresent(opts -> opts.forEach(this::setAndroidCapability));
}
}

Expand Down
15 changes: 15 additions & 0 deletions java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.OFF;
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.SEVERE;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
Expand Down Expand Up @@ -382,4 +383,18 @@ void shouldBeAbleToSetAnAndroidOption() {
.extractingByKey("androidActivity")
.isEqualTo("com.cheese.nom");
}

@Test
void shouldBeAbleToMergeAnAndroidOption() {
var original = new ChromeOptions();
original.setAndroidActivity("co_activity");
original.setAndroidPackage("co_package");
original.setExperimentalOption("experimental", "co_experimental");
original.addArguments("--co_argument");

var caps = new MutableCapabilities();
var merged = original.merge(caps);

assertEquals(original.asMap(), merged.asMap());
}
}

0 comments on commit 4a17ec3

Please sign in to comment.