Skip to content

Commit

Permalink
[java] Removing deprecated safari.options
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Sep 27, 2021
1 parent a3e4d1b commit ba05dd9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 88 deletions.
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/chrome/ChromeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public class ChromeDriverService extends DriverService {
* System property that defines whether the chromedriver executable should check for build
* version compatibility between chromedriver and the browser.
*/
public static final String
CHROME_DRIVER_DISABLE_BUILD_CHECK =
public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK =
"webdriver.chrome.disableBuildCheck";

/**
Expand Down
8 changes: 0 additions & 8 deletions java/src/org/openqa/selenium/safari/SafariDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ public int score(Capabilities capabilities) {
score++;
}

if (capabilities.getCapability(SafariOptions.CAPABILITY) != null) {
score++;
}

if (capabilities.getCapability("se:safari:techPreview") != null) {
score++;
}

return score;
}

Expand Down
95 changes: 40 additions & 55 deletions java/src/org/openqa/selenium/safari/SafariOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

package org.openqa.selenium.safari;

import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.AbstractDriverOptions;
import org.openqa.selenium.remote.BrowserType;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

/**
* Class to manage options specific to {@link SafariDriver}.
*
Expand All @@ -50,22 +49,9 @@ public class SafariOptions extends AbstractDriverOptions<SafariOptions> {

static final String SAFARI_TECH_PREVIEW = "Safari Technology Preview";

/**
* Key used to store SafariOptions in a {@link Capabilities} object.
* @deprecated No replacement. Use the methods on this class
*/
@Deprecated
public static final String CAPABILITY = "safari.options";

private interface Option {
// Defined by Apple
String AUTOMATIC_INSPECTION = "safari:automaticInspection";
String AUTOMATIC_PROFILING = "safari:automaticProfiling";
}

public SafariOptions() {
setUseTechnologyPreview(false);
setCapability(BROWSER_NAME, "safari");
setCapability(BROWSER_NAME, BrowserType.SAFARI);
}

public SafariOptions(Capabilities source) {
Expand All @@ -74,6 +60,21 @@ public SafariOptions(Capabilities source) {
source.getCapabilityNames().forEach(name -> setCapability(name, source.getCapability(name)));
}

/**
* Construct a {@link SafariOptions} instance from given capabilities.
*
* @param capabilities Desired capabilities from which the options are derived.
* @return SafariOptions
* @throws WebDriverException If an error occurred during the reconstruction of the options
*/
public static SafariOptions fromCapabilities(Capabilities capabilities)
throws WebDriverException {
if (capabilities instanceof SafariOptions) {
return (SafariOptions) capabilities;
}
return new SafariOptions(capabilities);
}

@Override
public SafariOptions merge(Capabilities extraCapabilities) {
Require.nonNull("Capabilities to merge", extraCapabilities);
Expand All @@ -87,27 +88,8 @@ public SafariOptions merge(Capabilities extraCapabilities) {
return newInstance;
}

/**
* Construct a {@link SafariOptions} instance from given capabilities.
* When the {@link #CAPABILITY} capability is set, all other capabilities will be ignored!
*
* @param capabilities Desired capabilities from which the options are derived.
* @return SafariOptions
* @throws WebDriverException If an error occurred during the reconstruction of the options
*/
public static SafariOptions fromCapabilities(Capabilities capabilities)
throws WebDriverException {
if (capabilities instanceof SafariOptions) {
return (SafariOptions) capabilities;
}
Object cap = capabilities.getCapability(SafariOptions.CAPABILITY);
if (cap instanceof SafariOptions) {
return (SafariOptions) cap;
} else if (cap instanceof Map) {
return new SafariOptions(new MutableCapabilities(((Map<String, ?>) cap)));
} else {
return new SafariOptions(capabilities);
}
public boolean getAutomaticInspection() {
return Boolean.TRUE.equals(getCapability(Option.AUTOMATIC_INSPECTION));
}

// Setters
Expand All @@ -124,45 +106,41 @@ public SafariOptions setAutomaticInspection(boolean automaticInspection) {
return this;
}

public boolean getAutomaticProfiling() {
return Boolean.TRUE.equals(is(Option.AUTOMATIC_PROFILING));
}

/**
* Instruct the SafariDriver to enable the Automatic profiling if true, otherwise disable
* the automatic profiling. Defaults to disabling the automatic profiling.
*
* @param automaticProfiling If true, the SafariDriver will enable the Automation Profiling,
* otherwise will disable.
* otherwise will disable.
*/
public SafariOptions setAutomaticProfiling(boolean automaticProfiling) {
setCapability(Option.AUTOMATIC_PROFILING, automaticProfiling);
return this;
}

// Getters

public boolean getUseTechnologyPreview() {
return SAFARI_TECH_PREVIEW.equals(getBrowserName());
}

/**
* Instruct the SafariDriver to use the Safari Technology Preview if true, otherwise use the
* release version of Safari. Defaults to using the release version of Safari.
*
* @param useTechnologyPreview If true, the SafariDriver will use the Safari Technology Preview,
* otherwise will use the release version of Safari.
* otherwise will use the release version of Safari.
*/
public SafariOptions setUseTechnologyPreview(boolean useTechnologyPreview) {
// Use an object here, rather than a boolean to avoid a stack overflow
super.setCapability(BROWSER_NAME, useTechnologyPreview ? SAFARI_TECH_PREVIEW : "safari");
return this;
}

// Getters

public boolean getAutomaticInspection() {
return Boolean.TRUE.equals(getCapability(Option.AUTOMATIC_INSPECTION));
}

public boolean getAutomaticProfiling() {
return Boolean.TRUE.equals(is(Option.AUTOMATIC_PROFILING));
}

public boolean getUseTechnologyPreview() {
return SAFARI_TECH_PREVIEW.equals(getBrowserName());
}

@Override
protected Set<String> getExtraCapabilityNames() {
return Collections.emptySet();
Expand All @@ -172,4 +150,11 @@ protected Set<String> getExtraCapabilityNames() {
protected Object getExtraCapability(String capabilityName) {
return null;
}

private interface Option {

// Defined by Apple
String AUTOMATIC_INSPECTION = "safari:automaticInspection";
String AUTOMATIC_PROFILING = "safari:automaticProfiling";
}
}
35 changes: 12 additions & 23 deletions java/test/org/openqa/selenium/safari/SafariOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@

package org.openqa.selenium.safari;

import static java.util.stream.Collectors.toSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.remote.AcceptedW3CCapabilityKeys;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.testing.UnitTests;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

@Category(UnitTests.class)
public class SafariOptionsTest {

Expand All @@ -50,28 +49,18 @@ public void roundTrippingToCapabilitiesAndBackWorks() {

@Test
public void canConstructFromCapabilities() {
Map<String, Object> embeddedOptions = new HashMap<>();
embeddedOptions.put("technologyPreview", true);

SafariOptions options = new SafariOptions();
assertThat(options.getUseTechnologyPreview()).isFalse();

options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "Safari Technology Preview"));
options = new SafariOptions(
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, SafariOptions.SAFARI_TECH_PREVIEW));
assertThat(options.getUseTechnologyPreview()).isTrue();

options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "safari"));
options = new SafariOptions(
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, BrowserType.SAFARI));
assertThat(options.getUseTechnologyPreview()).isFalse();
}

@Test
public void newerStyleCapabilityWinsOverOlderStyle() {
SafariOptions options = new SafariOptions(new ImmutableCapabilities(
CapabilityType.BROWSER_NAME, "Safari Technology Preview",
SafariOptions.CAPABILITY, singletonMap("technologyPreview", false)));

assertThat(options.getUseTechnologyPreview()).isTrue();
}

@Test
public void canSetAutomaticInspection() {
SafariOptions options = new SafariOptions().setAutomaticInspection(true);
Expand All @@ -87,13 +76,13 @@ public void canSetAutomaticProfiling() {
@Test
public void settingTechnologyPreviewModeAlsoChangesBrowserName() {
SafariOptions options = new SafariOptions();
assertThat(options.getBrowserName()).isEqualTo("safari");
assertThat(options.getBrowserName()).isEqualTo(BrowserType.SAFARI);

options.setUseTechnologyPreview(true);
assertThat(options.getBrowserName()).isEqualTo("Safari Technology Preview");
assertThat(options.getBrowserName()).isEqualTo(SafariOptions.SAFARI_TECH_PREVIEW);

options.setUseTechnologyPreview(false);
assertThat(options.getBrowserName()).isEqualTo("safari");
assertThat(options.getBrowserName()).isEqualTo(BrowserType.SAFARI);
}

@Test
Expand Down

0 comments on commit ba05dd9

Please sign in to comment.