From 7a13e937a5fad8e6e7e63188032b7648a73912af Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Tue, 28 Jun 2022 12:47:22 +0200 Subject: [PATCH] [java] Fixing - put all valid IEOptions only in se:ieOptions This is part of the work being done to remove JWP support from Java. Fixes #10822 --- .../selenium/ie/InternetExplorerOptions.java | 10 ++-- .../ie/InternetExplorerOptionsTest.java | 49 +++++++++---------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/java/src/org/openqa/selenium/ie/InternetExplorerOptions.java b/java/src/org/openqa/selenium/ie/InternetExplorerOptions.java index 23efe3b4d1a80..da79a9e60ba2e 100644 --- a/java/src/org/openqa/selenium/ie/InternetExplorerOptions.java +++ b/java/src/org/openqa/selenium/ie/InternetExplorerOptions.java @@ -103,12 +103,8 @@ public InternetExplorerOptions(Capabilities source) { @Override public InternetExplorerOptions merge(Capabilities extraCapabilities) { InternetExplorerOptions newInstance = new InternetExplorerOptions(); - this.asMap().entrySet().stream() - .filter(entry -> !entry.getKey().equals(IE_OPTIONS)) - .forEach(entry -> newInstance.setCapability(entry.getKey(), entry.getValue())); - extraCapabilities.asMap().entrySet().stream() - .filter(entry -> !entry.getKey().equals(IE_OPTIONS)) - .forEach(entry -> newInstance.setCapability(entry.getKey(), entry.getValue())); + this.asMap().forEach(newInstance::setCapability); + extraCapabilities.asMap().forEach(newInstance::setCapability); return newInstance; } @@ -245,7 +241,7 @@ public void setCapability(String key, Object value) { if (CAPABILITY_NAMES.contains(key)) { ieOptions.put(key, value); - } else if (!IE_OPTIONS.equals(key)) { + } else { // Regular, top level value super.setCapability(key, value); } diff --git a/java/test/org/openqa/selenium/ie/InternetExplorerOptionsTest.java b/java/test/org/openqa/selenium/ie/InternetExplorerOptionsTest.java index 02f4bc19ea144..d7541a18b0bc2 100644 --- a/java/test/org/openqa/selenium/ie/InternetExplorerOptionsTest.java +++ b/java/test/org/openqa/selenium/ie/InternetExplorerOptionsTest.java @@ -17,17 +17,8 @@ package org.openqa.selenium.ie; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.InstanceOfAssertFactories.LIST; -import static org.assertj.core.api.InstanceOfAssertFactories.MAP; -import static org.openqa.selenium.ie.InternetExplorerDriver.FORCE_CREATE_PROCESS; -import static org.openqa.selenium.ie.InternetExplorerDriver.IE_SWITCHES; -import static org.openqa.selenium.ie.InternetExplorerDriver.INITIAL_BROWSER_URL; -import static org.openqa.selenium.ie.InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS; -import static org.openqa.selenium.ie.InternetExplorerOptions.IE_OPTIONS; - -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; import org.openqa.selenium.Platform; @@ -36,6 +27,14 @@ import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.MAP; +import static org.openqa.selenium.ie.InternetExplorerDriver.FORCE_CREATE_PROCESS; +import static org.openqa.selenium.ie.InternetExplorerDriver.IE_SWITCHES; +import static org.openqa.selenium.ie.InternetExplorerDriver.INITIAL_BROWSER_URL; +import static org.openqa.selenium.ie.InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS; +import static org.openqa.selenium.ie.InternetExplorerOptions.IE_OPTIONS; + @Tag("UnitTests") public class InternetExplorerOptionsTest { @@ -51,26 +50,27 @@ public void shouldAllowACapabilityToBeSet() { public void shouldMirrorCapabilitiesForIeProperly() { String expected = "http://cheese.example.com"; InternetExplorerOptions options = new InternetExplorerOptions() - .withInitialBrowserUrl(expected); + .withInitialBrowserUrl(expected); Map map = options.asMap(); - assertThat(map).containsEntry(INITIAL_BROWSER_URL, expected); - assertThat(map).containsKey("se:ieOptions"); - assertThat(map.get("se:ieOptions")).asInstanceOf(MAP) - .containsEntry(INITIAL_BROWSER_URL, expected); + assertThat(map).containsKey(IE_OPTIONS); + assertThat(map.get(IE_OPTIONS)).asInstanceOf(MAP) + .containsEntry(INITIAL_BROWSER_URL, expected); } @Test public void shouldMirrorCapabilitiesFromPassedInIeOptions() { InternetExplorerOptions toMirror = new InternetExplorerOptions() - .introduceFlakinessByIgnoringSecurityDomains(); + .introduceFlakinessByIgnoringSecurityDomains(); // This is damn weird. InternetExplorerOptions options = new InternetExplorerOptions(); - options.setCapability("se:ieOptions", toMirror); + options.setCapability(IE_OPTIONS, toMirror); - assertThat(options.is(INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS)).isTrue(); + Map map = options.asMap(); + assertThat(map.get(IE_OPTIONS)).asInstanceOf(MAP) + .containsEntry(INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); } @Test @@ -80,8 +80,7 @@ public void shouldPopulateIeOptionsFromExistingCapabilitiesWhichLackThem() { InternetExplorerOptions options = new InternetExplorerOptions(caps); - assertThat(options.is(INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS)).isTrue(); - assertThat(options.getCapability("se:ieOptions")).asInstanceOf(MAP) + assertThat(options.getCapability(IE_OPTIONS)).asInstanceOf(MAP) .containsEntry(INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); } @@ -116,15 +115,13 @@ public void shouldSetIeOptionsCapabilityWhenConstructedFromExistingCapabilities( @Test public void mergingOptionsMergesArguments() { - InternetExplorerOptions one = new InternetExplorerOptions().useCreateProcessApiToLaunchIe().addCommandSwitches("-private"); + InternetExplorerOptions one = new InternetExplorerOptions() + .useCreateProcessApiToLaunchIe() + .addCommandSwitches("-private"); InternetExplorerOptions two = new InternetExplorerOptions(); - InternetExplorerOptions merged = one.merge(two); + InternetExplorerOptions merged = two.merge(one); Map asMap = merged.asMap(); - assertThat(asMap) - .containsEntry(FORCE_CREATE_PROCESS, true) - .extractingByKey(IE_SWITCHES).asInstanceOf(LIST) - .containsExactly("-private"); assertThat(asMap) .extractingByKey(IE_OPTIONS).asInstanceOf(MAP) .containsEntry(FORCE_CREATE_PROCESS, true)