27
27
import org .openqa .selenium .logging .LogType ;
28
28
import org .openqa .selenium .logging .NeedsLocalLogs ;
29
29
import org .openqa .selenium .logging .profiler .HttpProfilerLogEntry ;
30
+ import org .openqa .selenium .remote .http .ClientConfig ;
30
31
import org .openqa .selenium .remote .http .HttpClient ;
31
32
import org .openqa .selenium .remote .http .HttpRequest ;
32
33
import org .openqa .selenium .remote .http .HttpResponse ;
@@ -60,6 +61,10 @@ public HttpCommandExecutor(URL addressOfRemoteServer) {
60
61
this (emptyMap (), addressOfRemoteServer );
61
62
}
62
63
64
+ public HttpCommandExecutor (ClientConfig config ) {
65
+ this (emptyMap (), config , defaultClientFactory );
66
+ }
67
+
63
68
/**
64
69
* Creates an {@link HttpCommandExecutor} that supports non-standard
65
70
* {@code additionalCommands} in addition to the standard.
@@ -68,26 +73,42 @@ public HttpCommandExecutor(URL addressOfRemoteServer) {
68
73
* @param addressOfRemoteServer URL of remote end Selenium server
69
74
*/
70
75
public HttpCommandExecutor (
71
- Map <String , CommandInfo > additionalCommands ,
72
- URL addressOfRemoteServer ) {
76
+ Map <String , CommandInfo > additionalCommands ,
77
+ URL addressOfRemoteServer )
78
+ {
73
79
this (additionalCommands , addressOfRemoteServer , defaultClientFactory );
74
80
}
75
81
76
82
public HttpCommandExecutor (
77
- Map <String , CommandInfo > additionalCommands ,
78
- URL addressOfRemoteServer ,
79
- HttpClient .Factory httpClientFactory ) {
83
+ Map <String , CommandInfo > additionalCommands ,
84
+ URL addressOfRemoteServer ,
85
+ HttpClient .Factory httpClientFactory )
86
+ {
87
+ this (additionalCommands ,
88
+ ClientConfig .defaultConfig ().baseUrl (addressOfRemoteServer ),
89
+ httpClientFactory );
90
+ }
91
+
92
+ public HttpCommandExecutor (
93
+ Map <String , CommandInfo > additionalCommands ,
94
+ ClientConfig config ,
95
+ HttpClient .Factory httpClientFactory )
96
+ {
80
97
try {
81
- remoteServer = addressOfRemoteServer == null
82
- ? new URL (System .getProperty ("webdriver.remote.server" , "http://localhost:4444/" ))
83
- : addressOfRemoteServer ;
98
+ if (config .baseUri () != null ) {
99
+ remoteServer = config .baseUrl ();
100
+ } else {
101
+ remoteServer = new URL (
102
+ System .getProperty ("webdriver.remote.server" , "http://localhost:4444/" ));
103
+ config = config .baseUrl (remoteServer );
104
+ }
84
105
} catch (MalformedURLException e ) {
85
106
throw new WebDriverException (e );
86
107
}
87
108
88
109
this .additionalCommands = additionalCommands ;
89
110
this .httpClientFactory = httpClientFactory ;
90
- this .client = httpClientFactory .createClient (remoteServer );
111
+ this .client = httpClientFactory .createClient (config );
91
112
}
92
113
93
114
/**
@@ -126,7 +147,7 @@ public Response execute(Command command) throws IOException {
126
147
if (!GET_ALL_SESSIONS .equals (command .getName ())
127
148
&& !NEW_SESSION .equals (command .getName ())) {
128
149
throw new NoSuchSessionException (
129
- "Session ID is null. Using WebDriver after calling quit()?" );
150
+ "Session ID is null. Using WebDriver after calling quit()?" );
130
151
}
131
152
}
132
153
@@ -149,7 +170,7 @@ public Response execute(Command command) throws IOException {
149
170
150
171
if (commandCodec == null || responseCodec == null ) {
151
172
throw new WebDriverException (
152
- "No command or response codec has been defined. Unable to proceed" );
173
+ "No command or response codec has been defined. Unable to proceed" );
153
174
}
154
175
155
176
HttpRequest httpRequest = commandCodec .encode (command );
@@ -180,8 +201,8 @@ public Response execute(Command command) throws IOException {
180
201
} catch (UnsupportedCommandException e ) {
181
202
if (e .getMessage () == null || "" .equals (e .getMessage ())) {
182
203
throw new UnsupportedOperationException (
183
- "No information from server. Command name was: " + command .getName (),
184
- e .getCause ());
204
+ "No information from server. Command name was: " + command .getName (),
205
+ e .getCause ());
185
206
}
186
207
throw e ;
187
208
}
0 commit comments