Skip to content

Commit 57e9c69

Browse files
Grigory Mischenkobarancev
authored andcommitted
Using timeout in DriverService Builder
Removing timeout from FirefoxBinary because it is not used Signed-off-by: Alexei Barantsev <[email protected]>
1 parent b79e0b6 commit 57e9c69

22 files changed

+870
-38
lines changed

java/client/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.io.File;
3030
import java.io.IOException;
31+
import java.time.Duration;
3132

3233
/**
3334
* Manages the life and death of a ChromeDriver server.
@@ -85,7 +86,24 @@ public ChromeDriverService(
8586
int port,
8687
ImmutableList<String> args,
8788
ImmutableMap<String, String> environment) throws IOException {
88-
super(executable, port, args, environment);
89+
super(executable, port, DEFAULT_TIMEOUT, args, environment);
90+
}
91+
92+
/**
93+
* @param executable The chromedriver executable.
94+
* @param port Which port to start the ChromeDriver on.
95+
* @param timeout Timeout waiting for driver server to start.
96+
* @param args The arguments to the launched server.
97+
* @param environment The environment for the launched server.
98+
* @throws IOException If an I/O error occurs.
99+
*/
100+
public ChromeDriverService(
101+
File executable,
102+
int port,
103+
Duration timeout,
104+
ImmutableList<String> args,
105+
ImmutableMap<String, String> environment) throws IOException {
106+
super(executable, port, timeout, args, environment);
89107
}
90108

91109
/**
@@ -214,10 +232,11 @@ protected ImmutableList<String> createArgs() {
214232
protected ChromeDriverService createDriverService(
215233
File exe,
216234
int port,
235+
Duration timeout,
217236
ImmutableList<String> args,
218237
ImmutableMap<String, String> environment) {
219238
try {
220-
return new ChromeDriverService(exe, port, args, environment);
239+
return new ChromeDriverService(exe, port, timeout, args, environment);
221240
} catch (IOException e) {
222241
throw new WebDriverException(e);
223242
}

java/client/src/org/openqa/selenium/edge/ChromiumEdgeDriverService.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.io.File;
2929
import java.io.IOException;
30+
import java.time.Duration;
3031
import java.util.List;
3132
import java.util.Map;
3233

@@ -49,7 +50,16 @@ public ChromiumEdgeDriverService(
4950
int port,
5051
List<String> args,
5152
Map<String, String> environment) throws IOException {
52-
super(executable, port, args, environment);
53+
super(executable, port, DEFAULT_TIMEOUT, args, environment);
54+
}
55+
56+
public ChromiumEdgeDriverService(
57+
File executable,
58+
int port,
59+
Duration timeout,
60+
List<String> args,
61+
Map<String, String> environment) throws IOException {
62+
super(executable, port, timeout, args, environment);
5363
}
5464

5565
/**
@@ -169,10 +179,11 @@ protected ImmutableList<String> createArgs() {
169179
protected ChromiumEdgeDriverService createDriverService(
170180
File exe,
171181
int port,
182+
Duration timeout,
172183
ImmutableList<String> args,
173184
ImmutableMap<String, String> environment) {
174185
try {
175-
return new ChromiumEdgeDriverService(exe, port, args, environment);
186+
return new ChromiumEdgeDriverService(exe, port, timeout, args, environment);
176187
} catch (IOException e) {
177188
throw new WebDriverException(e);
178189
}

java/client/src/org/openqa/selenium/edge/EdgeDriverService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.io.File;
2424
import java.io.IOException;
25+
import java.time.Duration;
2526
import java.util.List;
2627
import java.util.Map;
2728

@@ -50,16 +51,18 @@ public abstract class EdgeDriverService extends DriverService {
5051
/**
5152
* @param executable The EdgeDriver executable.
5253
* @param port Which port to start the EdgeDriver on.
54+
* @param timeout Timeout waiting for driver server to start.
5355
* @param args The arguments to the launched server.
5456
* @param environment The environment for the launched server.
5557
* @throws IOException If an I/O error occurs.
5658
*/
5759
public EdgeDriverService(
5860
File executable,
5961
int port,
62+
Duration timeout,
6063
List<String> args,
6164
Map<String, String> environment) throws IOException {
62-
super(executable, port, ImmutableList.copyOf(args), ImmutableMap.copyOf(environment));
65+
super(executable, port, timeout, ImmutableList.copyOf(args), ImmutableMap.copyOf(environment));
6366
}
6467

6568
public static abstract class Builder<DS extends EdgeDriverService, B extends EdgeDriverService.Builder<?, ?>>

java/client/src/org/openqa/selenium/edge/edgehtml/EdgeHtmlDriverService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.File;
3030
import java.io.FileOutputStream;
3131
import java.io.IOException;
32+
import java.time.Duration;
3233
import java.util.List;
3334
import java.util.Map;
3435

@@ -37,7 +38,14 @@ public class EdgeHtmlDriverService extends EdgeDriverService {
3738
public EdgeHtmlDriverService(File executable, int port,
3839
List<String> args,
3940
Map<String, String> environment) throws IOException {
40-
super(executable, port, args, environment);
41+
super(executable, port, DEFAULT_TIMEOUT, args, environment);
42+
}
43+
44+
public EdgeHtmlDriverService(File executable, int port,
45+
Duration timeout,
46+
List<String> args,
47+
Map<String, String> environment) throws IOException {
48+
super(executable, port, timeout, args, environment);
4149
}
4250

4351
/**
@@ -106,11 +114,12 @@ protected ImmutableList<String> createArgs() {
106114

107115
@Override
108116
protected EdgeHtmlDriverService createDriverService(File exe, int port,
117+
Duration timeout,
109118
ImmutableList<String> args,
110119
ImmutableMap<String, String> environment) {
111120
try {
112121
EdgeHtmlDriverService
113-
service = new EdgeHtmlDriverService(exe, port, args, environment);
122+
service = new EdgeHtmlDriverService(exe, port, timeout, args, environment);
114123

115124
if (getLogFile() != null) {
116125
service.sendOutputTo(new FileOutputStream(getLogFile()));

java/client/src/org/openqa/selenium/firefox/FirefoxBinary.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.firefox;
1919

2020
import static java.util.Arrays.stream;
21-
import static java.util.concurrent.TimeUnit.SECONDS;
2221
import static java.util.stream.Collectors.toList;
2322
import static org.openqa.selenium.Platform.MAC;
2423
import static org.openqa.selenium.Platform.UNIX;
@@ -80,7 +79,6 @@ public static Channel fromString(String name) {
8079

8180
private final List<String> extraOptions = new ArrayList<>();
8281
private final Executable executable;
83-
private long timeout = SECONDS.toMillis(45);
8482

8583
public FirefoxBinary() {
8684
Executable systemBinary = locateFirefoxBinaryFromSystemProperty();
@@ -142,14 +140,6 @@ public List<String> getExtraOptions() {
142140
return extraOptions;
143141
}
144142

145-
public long getTimeout() {
146-
return timeout;
147-
}
148-
149-
public void setTimeout(long timeout) {
150-
this.timeout = timeout;
151-
}
152-
153143
@Override
154144
public String toString() {
155145
return "FirefoxBinary(" + executable.getPath() + ")";

java/client/src/org/openqa/selenium/firefox/FirefoxDriverService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,25 @@
2424

2525
import java.io.File;
2626
import java.io.IOException;
27+
import java.time.Duration;
2728

2829
public abstract class FirefoxDriverService extends DriverService {
2930

3031
/**
3132
* @param executable The GeckoDriver executable.
3233
* @param port Which port to start the GeckoDriver on.
34+
* @param timeout Timeout waiting for driver server to start.
3335
* @param args The arguments to the launched server.
3436
* @param environment The environment for the launched server.
3537
* @throws IOException If an I/O error occurs.
3638
*/
3739
public FirefoxDriverService(
3840
File executable,
3941
int port,
42+
Duration timeout,
4043
ImmutableList<String> args,
4144
ImmutableMap<String, String> environment) throws IOException {
42-
super(executable, port, args, environment);
45+
super(executable, port, timeout, args, environment);
4346
}
4447

4548
public static abstract class Builder<DS extends FirefoxDriverService, B extends FirefoxDriverService.Builder<?, ?>>

java/client/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.openqa.selenium.firefox;
1919

2020
import static com.google.common.base.Preconditions.checkNotNull;
21-
import static java.util.concurrent.TimeUnit.SECONDS;
21+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2222

2323
import com.google.auto.service.AutoService;
2424
import com.google.common.collect.ImmutableList;
@@ -34,6 +34,7 @@
3434
import java.io.File;
3535
import java.io.FileOutputStream;
3636
import java.io.IOException;
37+
import java.time.Duration;
3738

3839
/**
3940
* Manages the life and death of an GeckoDriver aka 'wires'.
@@ -58,7 +59,24 @@ public GeckoDriverService(
5859
int port,
5960
ImmutableList<String> args,
6061
ImmutableMap<String, String> environment) throws IOException {
61-
super(executable, port, args, environment);
62+
super(executable, port, DEFAULT_TIMEOUT, args, environment);
63+
}
64+
65+
/**
66+
* @param executable The GeckoDriver executable.
67+
* @param port Which port to start the GeckoDriver on.
68+
* @param timeout Timeout waiting for driver server to start.
69+
* @param args The arguments to the launched server.
70+
* @param environment The environment for the launched server.
71+
* @throws IOException If an I/O error occurs.
72+
*/
73+
public GeckoDriverService(
74+
File executable,
75+
int port,
76+
Duration timeout,
77+
ImmutableList<String> args,
78+
ImmutableMap<String, String> environment) throws IOException {
79+
super(executable, port, timeout, args, environment);
6280
}
6381

6482
/**
@@ -96,7 +114,7 @@ static GeckoDriverService createDefaultService(Capabilities caps) {
96114

97115
@Override
98116
protected void waitUntilAvailable() {
99-
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
117+
PortProber.waitForPortUp(getUrl().getPort(), (int) getTimeout().toMillis(), MILLISECONDS);
100118
}
101119

102120
@Override
@@ -181,10 +199,11 @@ protected ImmutableList<String> createArgs() {
181199

182200
@Override
183201
protected GeckoDriverService createDriverService(File exe, int port,
202+
Duration timeout,
184203
ImmutableList<String> args,
185204
ImmutableMap<String, String> environment) {
186205
try {
187-
GeckoDriverService service = new GeckoDriverService(exe, port, args, environment);
206+
GeckoDriverService service = new GeckoDriverService(exe, port, timeout, args, environment);
188207
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
189208
if (firefoxLogFile != null) { // System property has higher precedence
190209
if ("/dev/stdout".equals(firefoxLogFile)) {

java/client/src/org/openqa/selenium/firefox/xpi/XpiDriverService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.io.IOException;
5050
import java.net.MalformedURLException;
5151
import java.net.URL;
52+
import java.time.Duration;
5253
import java.util.ArrayList;
5354
import java.util.HashSet;
5455
import java.util.List;
@@ -77,13 +78,14 @@ public class XpiDriverService extends FirefoxDriverService {
7778
private XpiDriverService(
7879
File executable,
7980
int port,
81+
Duration timeout,
8082
ImmutableList<String> args,
8183
ImmutableMap<String, String> environment,
8284
FirefoxBinary binary,
8385
FirefoxProfile profile,
8486
File logFile)
8587
throws IOException {
86-
super(executable, port, args, environment);
88+
super(executable, port, timeout, args, environment);
8789

8890
Preconditions.checkState(port > 0, "Port must be set");
8991

@@ -410,16 +412,23 @@ protected ImmutableList<String> createArgs() {
410412
return ImmutableList.of("-foreground");
411413
}
412414

415+
@Override
416+
protected Duration getDefaultTimeout() {
417+
return Duration.ofSeconds(45);
418+
}
419+
413420
@Override
414421
protected XpiDriverService createDriverService(
415422
File exe,
416423
int port,
424+
Duration timeout,
417425
ImmutableList<String> args,
418426
ImmutableMap<String, String> environment) {
419427
try {
420428
return new XpiDriverService(
421429
exe,
422430
port,
431+
timeout,
423432
args,
424433
environment,
425434
binary == null ? new FirefoxBinary() : binary,

java/client/src/org/openqa/selenium/ie/InternetExplorerDriverService.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.io.File;
3030
import java.io.IOException;
31+
import java.time.Duration;
3132

3233
/**
3334
* Manages the life and death of an IEDriverServer.
@@ -76,7 +77,21 @@ public class InternetExplorerDriverService extends DriverService {
7677
*/
7778
private InternetExplorerDriverService(File executable, int port, ImmutableList<String> args,
7879
ImmutableMap<String, String> environment) throws IOException {
79-
super(executable, port, args, environment);
80+
super(executable, port, DEFAULT_TIMEOUT, args, environment);
81+
}
82+
83+
/**
84+
*
85+
* @param executable The IEDriverServer executable.
86+
* @param port Which port to start the IEDriverServer on.
87+
* @param timeout Timeout waiting for driver server to start.
88+
* @param args The arguments to the launched server.
89+
* @param environment The environment for the launched server.
90+
* @throws IOException If an I/O error occurs.
91+
*/
92+
private InternetExplorerDriverService(File executable, int port, Duration timeout, ImmutableList<String> args,
93+
ImmutableMap<String, String> environment) throws IOException {
94+
super(executable, port, timeout, args, environment);
8095
}
8196

8297
/**
@@ -104,14 +119,14 @@ public static class Builder extends DriverService.Builder<
104119
private Boolean silent = null;
105120

106121
@Override
107-
public int score(Capabilities capabilities) {
122+
public int score(Capabilities capabilites) {
108123
int score = 0;
109124

110-
if (BrowserType.IE.equals(capabilities.getBrowserName())) {
125+
if (BrowserType.IE.equals(capabilites.getBrowserName())) {
111126
score++;
112127
}
113128

114-
if (capabilities.getCapability(InternetExplorerOptions.IE_OPTIONS) != null) {
129+
if (capabilites.getCapability(InternetExplorerOptions.IE_OPTIONS) != null) {
115130
score++;
116131
}
117132

@@ -225,10 +240,11 @@ protected ImmutableList<String> createArgs() {
225240

226241
@Override
227242
protected InternetExplorerDriverService createDriverService(File exe, int port,
243+
Duration timeout,
228244
ImmutableList<String> args,
229245
ImmutableMap<String, String> environment) {
230246
try {
231-
return new InternetExplorerDriverService(exe, port, args, environment);
247+
return new InternetExplorerDriverService(exe, port, timeout, args, environment);
232248
} catch (IOException e) {
233249
throw new WebDriverException(e);
234250
}

0 commit comments

Comments
 (0)