From a67f8808f9bfa546ae089e47589bbd885cb18dc0 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Fri, 1 Dec 2017 16:49:41 +0300 Subject: [PATCH] Fixing ability to construct SafariOptions from capabilities object --- .../openqa/selenium/safari/SafariOptions.java | 26 ++++++++++++++++--- .../selenium/safari/SafariOptionsTest.java | 9 +++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/java/client/src/org/openqa/selenium/safari/SafariOptions.java b/java/client/src/org/openqa/selenium/safari/SafariOptions.java index 3fe7fb18aaa36..0920b5e4f07f3 100644 --- a/java/client/src/org/openqa/selenium/safari/SafariOptions.java +++ b/java/client/src/org/openqa/selenium/safari/SafariOptions.java @@ -147,7 +147,6 @@ SafariOptions setPort(int port) { */ public SafariOptions useCleanSession(boolean useCleanSession) { options.put(Option.CLEAN_SESSION, useCleanSession); - setCapability(Option.CLEAN_SESSION, useCleanSession); return this; } @@ -165,15 +164,34 @@ public SafariOptions setUseCleanSession(boolean useCleanSession) { * * @param useTechnologyPreview If true, the SafariDriver will use the Safari Technology Preview, * otherwise will use the release version of Safari. - * @deprecated Create a {@link SafariDriverService} to specify what Safari flavour should be used - * and pass the service instance to a {@link SafariDriver} constructor. */ - @Deprecated public SafariOptions setUseTechnologyPreview(boolean useTechnologyPreview) { options.put(Option.TECHNOLOGY_PREVIEW, useTechnologyPreview); return this; } + @Override + public void setCapability(String key, Object value) { + if (Option.TECHNOLOGY_PREVIEW.equals(key)) { + setUseTechnologyPreview(Boolean.valueOf(value.toString())); + } else if (Option.CLEAN_SESSION.equals(key)) { + useCleanSession(Boolean.valueOf(value.toString())); + } else { + super.setCapability(key, value); + } + } + + @Override + public void setCapability(String key, boolean value) { + if (Option.TECHNOLOGY_PREVIEW.equals(key)) { + setUseTechnologyPreview(value); + } else if (Option.CLEAN_SESSION.equals(key)) { + useCleanSession(value); + } else { + super.setCapability(key, value); + } + } + public SafariOptions setProxy(Proxy proxy) { setCapability(CapabilityType.PROXY, proxy); return this; diff --git a/java/client/test/org/openqa/selenium/safari/SafariOptionsTest.java b/java/client/test/org/openqa/selenium/safari/SafariOptionsTest.java index 29c632950fbfb..98d2fddbe6317 100644 --- a/java/client/test/org/openqa/selenium/safari/SafariOptionsTest.java +++ b/java/client/test/org/openqa/selenium/safari/SafariOptionsTest.java @@ -51,4 +51,13 @@ public void roundTrippingToCapabilitiesAndBackWorks() { assertEquals(expected, seen); } + @Test + public void canConstructFromCapabilities() { + SafariOptions options = new SafariOptions( + new ImmutableCapabilities("cleanSession", true, "technologyPreview", true)); + + assertTrue(options.getUseCleanSession()); + assertTrue(options.getUseTechnologyPreview()); + } + }