Skip to content

Commit 2a4fb06

Browse files
hypnocelukeis
authored andcommitted
Fixes #2680. Use port to check safaridriver availability. Ensure the new safari driver receives non null required capabilities. (#2685)
1 parent a435a8d commit 2a4fb06

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

java/client/src/org/openqa/selenium/safari/SafariDriver.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,32 @@ public SafariDriver(Capabilities desiredCapabilities) {
7575
* @param safariOptions safari specific options / capabilities for the driver
7676
*/
7777
public SafariDriver(SafariOptions safariOptions) {
78-
super(getExecutor(safariOptions), safariOptions.toCapabilities());
78+
super(getExecutor(safariOptions), safariOptions.toCapabilities(), requiredCapabilities(safariOptions));
79+
}
80+
81+
/**
82+
* Ensure the new safaridriver receives non null required capabilities.
83+
*/
84+
private static Capabilities requiredCapabilities(SafariOptions options) {
85+
if (isLegacy(options)) {
86+
return null;
87+
}
88+
return new DesiredCapabilities();
7989
}
8090

8191
private static CommandExecutor getExecutor(SafariOptions options) {
82-
Object useLegacy = options.toCapabilities().getCapability(USE_LEGACY_DRIVER_CAPABILITY);
8392
SafariDriverService service = SafariDriverService.createDefaultService(options);
84-
if ((useLegacy == null || !(Boolean)useLegacy) && service != null) {
93+
if (isLegacy(options) && service != null) {
8594
return new DriverCommandExecutor(service);
8695
}
8796
return new SafariDriverCommandExecutor(options);
8897
}
8998

99+
private static boolean isLegacy(SafariOptions options) {
100+
Object useLegacy = options.toCapabilities().getCapability(USE_LEGACY_DRIVER_CAPABILITY);
101+
return useLegacy != null && (Boolean)useLegacy;
102+
}
103+
90104
@Override
91105
public void setFileDetector(FileDetector detector) {
92106
throw new WebDriverException(

java/client/src/org/openqa/selenium/safari/SafariDriverService.java

+14
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717

1818
package org.openqa.selenium.safari;
1919

20+
import static java.util.concurrent.TimeUnit.SECONDS;
21+
2022
import com.google.common.collect.ImmutableList;
2123
import com.google.common.collect.ImmutableMap;
2224

2325
import org.openqa.selenium.WebDriverException;
26+
import org.openqa.selenium.net.PortProber;
2427
import org.openqa.selenium.remote.service.DriverService;
2528

2629
import java.io.File;
2730
import java.io.IOException;
31+
import java.net.MalformedURLException;
32+
import java.util.concurrent.ExecutionException;
2833

2934
public class SafariDriverService extends DriverService {
3035

@@ -42,6 +47,15 @@ public static SafariDriverService createDefaultService(SafariOptions options) {
4247
return null;
4348
}
4449

50+
@Override
51+
protected void waitUntilAvailable() throws MalformedURLException {
52+
try {
53+
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
54+
} catch (Exception e) {
55+
e.printStackTrace();
56+
}
57+
}
58+
4559
public static class Builder extends DriverService.Builder<
4660
SafariDriverService, SafariDriverService.Builder> {
4761

0 commit comments

Comments
 (0)