Skip to content

Commit

Permalink
[java] Fixing - put all valid IEOptions only in se:ieOptions
Browse files Browse the repository at this point in the history
This is part of the work being done to remove JWP
support from Java.

Fixes #10822
  • Loading branch information
diemol committed Jun 28, 2022
1 parent cc79de6 commit 7a13e93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
10 changes: 3 additions & 7 deletions java/src/org/openqa/selenium/ie/InternetExplorerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
49 changes: 23 additions & 26 deletions java/test/org/openqa/selenium/ie/InternetExplorerOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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<String, Object> 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<String, Object> map = options.asMap();
assertThat(map.get(IE_OPTIONS)).asInstanceOf(MAP)
.containsEntry(INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
}

@Test
Expand All @@ -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);
}

Expand Down Expand Up @@ -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<String, Object> 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)
Expand Down

0 comments on commit 7a13e93

Please sign in to comment.