Skip to content

Commit

Permalink
Implementing safari-specific capability matcher that takes into accou…
Browse files Browse the repository at this point in the history
…nt "technologyPreview" capability.
  • Loading branch information
barancev committed Nov 13, 2017
1 parent 0d98a99 commit c1f7cb0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.safari.SafariOptions;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -123,12 +123,30 @@ public Boolean apply(Map<String, Object> providedCapabilities, Map<String, Objec
}
}

class SafariSpecificValidator implements Validator {
@Override
public Boolean apply(Map<String, Object> providedCapabilities, Map<String, Object> requestedCapabilities) {
if (! "safari".equals(requestedCapabilities.get(CapabilityType.BROWSER_NAME))) {
return true;
}
SafariOptions requestedOptions = new SafariOptions(new ImmutableCapabilities(requestedCapabilities));
if (requestedOptions.getUseTechnologyPreview()) {
return providedCapabilities.get("technologyPreview") != null
&& Boolean.valueOf(providedCapabilities.get("technologyPreview").toString());
} else {
return providedCapabilities.get("technologyPreview") == null
|| !Boolean.valueOf(providedCapabilities.get("technologyPreview").toString());
}
}
}

private final List<Validator> validators = ImmutableList.of(
new PlatformValidator(),
new AliasedPropertyValidator(CapabilityType.BROWSER_NAME, "browser"),
new AliasedPropertyValidator(CapabilityType.BROWSER_VERSION, CapabilityType.VERSION),
new SimplePropertyValidator(CapabilityType.APPLICATION_NAME),
new FirefoxSpecificValidator()
new FirefoxSpecificValidator(),
new SafariSpecificValidator()
);

public boolean matches(Map<String, Object> providedCapabilities, Map<String, Object> requestedCapabilities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariOptions;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -149,14 +151,10 @@ public void shouldMatchLegacyFirefoxDriverOnly() {

Map<String, Object> legacyNode = new HashMap<>();
legacyNode.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
legacyNode.put(CapabilityType.PLATFORM, Platform.LINUX);
legacyNode.put(CapabilityType.VERSION, "52");
legacyNode.put(FirefoxDriver.MARIONETTE, false);

Map<String, Object> mNode = new HashMap<>();
mNode.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
mNode.put(CapabilityType.PLATFORM, Platform.LINUX);
mNode.put(CapabilityType.VERSION, "58");

assertTrue(matcher.matches(legacyNode, requested));
assertFalse(matcher.matches(mNode, requested));
Expand All @@ -168,17 +166,47 @@ public void shouldMatchMarionetteFirefoxDriverOnly() {

Map<String, Object> legacyNode = new HashMap<>();
legacyNode.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
legacyNode.put(CapabilityType.PLATFORM, Platform.LINUX);
legacyNode.put(CapabilityType.VERSION, "52");
legacyNode.put(FirefoxDriver.MARIONETTE, false);

Map<String, Object> mNode = new HashMap<>();
mNode.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
mNode.put(CapabilityType.PLATFORM, Platform.LINUX);
mNode.put(CapabilityType.VERSION, "58");

assertFalse(matcher.matches(legacyNode, requested));
assertTrue(matcher.matches(mNode, requested));
}

@Test
public void shouldMatchSafariTechnologyPreviewOnly() {
Map<String, Object> requested = new SafariOptions().setUseTechnologyPreview(true).asMap();

Map<String, Object> tpNode = new HashMap<>();
tpNode.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
tpNode.put(CapabilityType.PLATFORM, Platform.MAC);
tpNode.put("technologyPreview", true);

Map<String, Object> regularNode = new HashMap<>();
regularNode.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
regularNode.put(CapabilityType.PLATFORM, Platform.MAC);

assertTrue(matcher.matches(tpNode, requested));
assertFalse(matcher.matches(regularNode, requested));
}

@Test
public void shouldMatchRegularSafariOnly() {
Map<String, Object> requested = new SafariOptions().asMap();

Map<String, Object> tpNode = new HashMap<>();
tpNode.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
tpNode.put(CapabilityType.PLATFORM, Platform.MAC);
tpNode.put("technologyPreview", true);

Map<String, Object> regularNode = new HashMap<>();
regularNode.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
regularNode.put(CapabilityType.PLATFORM, Platform.MAC);

assertFalse(matcher.matches(tpNode, requested));
assertTrue(matcher.matches(regularNode, requested));
}

}

0 comments on commit c1f7cb0

Please sign in to comment.