From 4a17ec391c1787d3b3c258ea439c8f9e5f4b4146 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 13 Jul 2024 05:37:32 +0700 Subject: [PATCH] [java] Merge android specific parameters in chrome options (#14217) * added androidOptions in merge method * applied suggestions * applying format.sh * import assertEquals * fix for importi Optional --------- Co-authored-by: Diego Molina --- .../selenium/chromium/ChromiumOptions.java | 19 +++++++------------ .../selenium/chrome/ChromeOptionsTest.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java index 6f93930787217..b23ce29d2a567 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java @@ -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; @@ -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)); } } diff --git a/java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java b/java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java index aa19e2bdbb0c2..7cbece6b253eb 100644 --- a/java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java +++ b/java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java @@ -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; @@ -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()); + } }