Skip to content

Commit

Permalink
Deleting SafariOptions.port, if a user wants to run safaridriver on a…
Browse files Browse the repository at this point in the history
… specific port it should explicitly instantiate SafariDriverService and pass it to SafariDriver constructor
  • Loading branch information
barancev committed Mar 6, 2018
1 parent d289954 commit 4832457
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

public class SafariDriverService extends DriverService {

Expand All @@ -49,12 +48,11 @@ public static SafariDriverService createDefaultService() {
/**
* Use {@link #createDefaultService()} instead.
*/
@Deprecated
public static SafariDriverService createDefaultService(SafariOptions options) {
File exe = options.getUseTechnologyPreview() ?
TP_SAFARI_DRIVER_EXECUTABLE : SAFARI_DRIVER_EXECUTABLE;
if (exe.exists()) {
return new Builder().usingPort(options.getPort()).usingDriverExecutable(exe).build();
return new Builder().usingDriverExecutable(exe).build();
}
throw new WebDriverException("SafariDriver requires Safari 10 running on OSX El Capitan or greater.");
}
Expand All @@ -64,7 +62,7 @@ static SafariDriverService createDefaultService(Capabilities caps) {
}

@Override
protected void waitUntilAvailable() throws MalformedURLException {
protected void waitUntilAvailable() {
try {
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
} catch (RuntimeException e) {
Expand Down
43 changes: 2 additions & 41 deletions java/client/src/org/openqa/selenium/safari/SafariOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;

import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -56,14 +55,11 @@ public class SafariOptions extends MutableCapabilities {
private interface Option {
String CLEAN_SESSION = "cleanSession";
String TECHNOLOGY_PREVIEW = "technologyPreview";
String PORT = "port";
}

private Map<String, Object> options = new TreeMap<>();

public SafariOptions() {
options.put(Option.PORT, 0);

setUseTechnologyPreview(false);
useCleanSession(false);

Expand Down Expand Up @@ -108,33 +104,14 @@ public static SafariOptions fromCapabilities(Capabilities capabilities)
if (cap instanceof SafariOptions) {
return (SafariOptions) cap;
} else if (cap instanceof Map) {
try {
return SafariOptions.fromJsonMap((Map<?, ?>) cap);
} catch (IOException e) {
throw new WebDriverException(e);
}
return SafariOptions.fromJsonMap((Map<?, ?>) cap);
} else {
return new SafariOptions();
}
}

// Setters

/**
* Set the port the {@link SafariDriverService} should be started on. Defaults to 0, in which case
* the server selects a free port.
*
* @param port The port the {@link SafariDriverService} should be started on,
* or 0 if the server should select a free port.
* @deprecated Create a {@link SafariDriverService} to specify driver service port and pass
* the service instance to a {@link SafariDriver} constructor.
*/
@Deprecated
SafariOptions setPort(int port) {
options.put(Option.PORT, port);
return this;
}

/**
* Instruct the SafariDriver to delete all existing session data when starting a new session.
* This includes browser history, cache, cookies, HTML5 local storage, and HTML5 databases.
Expand Down Expand Up @@ -199,17 +176,6 @@ public SafariOptions setProxy(Proxy proxy) {

// Getters

/**
* @return The port the {@link SafariDriverService} should be started on.
* If 0, the server should select a free port.
* @see #setPort(int)
* @deprecated Getters are not needed in browser Options classes.
*/
@Deprecated
public int getPort() {
return ((Number) options.getOrDefault(Option.PORT, 0)).intValue();
}

/**
* @return Whether the SafariDriver should erase all session data before launching Safari.
* @see #setUseCleanSession(boolean)
Expand All @@ -235,14 +201,9 @@ public boolean getUseTechnologyPreview() {
*
* @return A {@link SafariOptions} instance associated with these extensions.
*/
private static SafariOptions fromJsonMap(Map<?, ?> options) throws IOException {
private static SafariOptions fromJsonMap(Map<?, ?> options) {
SafariOptions safariOptions = new SafariOptions();

Number port = (Number) options.get(Option.PORT);
if (port != null) {
safariOptions.setPort(port.intValue());
}

Boolean useCleanSession = (Boolean) options.get(Option.CLEAN_SESSION);
if (useCleanSession != null) {
safariOptions.useCleanSession(useCleanSession);
Expand Down

0 comments on commit 4832457

Please sign in to comment.