-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add methods to options classes for w3c compliant capabilities #9828
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,20 @@ | |
|
||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.openqa.selenium.PageLoadStrategy; | ||
import org.openqa.selenium.UnexpectedAlertBehaviour; | ||
import org.openqa.selenium.remote.AcceptedW3CCapabilityKeys; | ||
import org.openqa.selenium.testing.TestUtilities; | ||
import org.openqa.selenium.testing.UnitTests; | ||
|
||
import java.io.File; | ||
import java.time.Duration; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.stream.Collectors.toSet; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
@@ -67,6 +70,53 @@ public void canBuildLogLevelFromStringRepresentation() { | |
assertThat(ChromeDriverLogLevel.fromString("SEVERE")).isEqualTo(SEVERE); | ||
} | ||
|
||
@Test | ||
public void canAddW3CCompliantOptions() { | ||
ChromeOptions chromeOptions = new ChromeOptions(); | ||
chromeOptions.setBrowserVersion("99") | ||
.setPlatformName("9 3/4") | ||
.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE) | ||
.setAcceptInsecureCerts(true) | ||
.setPageLoadStrategy(PageLoadStrategy.EAGER) | ||
.setStrictFileInteractability(true) | ||
.setImplicitWaitTimeout(Duration.ofSeconds(1)) | ||
.setPageLoadTimeout(Duration.ofSeconds(2)) | ||
.setScriptTimeout(Duration.ofSeconds(3)); | ||
|
||
Map<String, Object> mappedOptions = chromeOptions.asMap(); | ||
assertThat(mappedOptions.get("browserName")).isEqualTo("chrome"); | ||
assertThat(mappedOptions.get("browserVersion")).isEqualTo("99"); | ||
assertThat(mappedOptions.get("platformName")).isEqualTo("9 3/4"); | ||
assertThat(mappedOptions.get("unhandledPromptBehavior").toString()).isEqualTo("ignore"); | ||
assertThat(mappedOptions.get("acceptInsecureCerts")).isEqualTo(true); | ||
assertThat(mappedOptions.get("pageLoadStrategy").toString()).isEqualTo("eager"); | ||
assertThat(mappedOptions.get("strictFileInteractability")).isEqualTo(true); | ||
|
||
Map<String, Long> expectedTimeouts = new HashMap<>(); | ||
expectedTimeouts.put("implicit", 1000L); | ||
expectedTimeouts.put("pageLoad", 2000L); | ||
expectedTimeouts.put("script", 3000L); | ||
|
||
assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts")); | ||
} | ||
|
||
@Test | ||
public void canAddSequentialTimeouts() { | ||
ChromeOptions chromeOptions = new ChromeOptions(); | ||
chromeOptions.setImplicitWaitTimeout(Duration.ofSeconds(1)); | ||
|
||
Map<String, Object> mappedOptions = chromeOptions.asMap(); | ||
Map<String, Long> expectedTimeouts = new HashMap<>(); | ||
|
||
expectedTimeouts.put("implicit", 1000L); | ||
assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts")); | ||
|
||
chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2)); | ||
expectedTimeouts.put("pageLoad", 2000L); | ||
Map<String, Object> mappedOptions2 = chromeOptions.asMap(); | ||
assertThat(expectedTimeouts).isEqualTo(mappedOptions2.get("timeouts")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps: ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setImplicitWaitTimeout(Duration.ofSeconds(1));
assertThat(chromeOptions.getCapability(TIMEOUTS)).isEqualTo(Map.of("implicit", 1000L);
chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2));
assertThat(chromeOptions.getCapability(TIMEOUTS)).isEqualTo(Map.of("implicit", 1000L, "page", 2000L); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to convert the options to an intermediate map. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, doesn't make sense if needing to look at existing capabilities |
||
} | ||
|
||
@Test | ||
public void mergingOptionsMergesArguments() { | ||
ChromeOptions one = new ChromeOptions().addArguments("verbose"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to avoid this variable. Consider a user doing:
I think a user would expect both timeouts to have been set, but the current implementation would only set one. I also think the opposite case (where the timeouts capability is set after calling the specific method) would mean that the user would expect the timeout map they passed in to be used.
One drawback to doing this is that you can't expect the
Map
the user passes in to be mutable. You'll need a check like:Finally, it's good practice to make the collection "unmodifiable" when we set it, to prevent users from changing state in unexpected ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I put this in a private
getCapabilities()
method. I'm not sure the reason forinstanceof Map
conditional. What alternative object is valid that will start a session?