18
18
import java .time .Duration ;
19
19
import java .util .*;
20
20
import java .util .stream .Collectors ;
21
+ import org .apache .http .client .config .RequestConfig ;
21
22
import org .openqa .selenium .By ;
22
23
import org .openqa .selenium .WebElement ;
23
24
import org .openqa .selenium .remote .RemoteWebDriver ;
@@ -47,6 +48,7 @@ public static class Builder {
47
48
private Boolean hideScrollBars ;
48
49
private DiffingMethodSensitivity diffingMethodSensitivity ;
49
50
private DiffingMethodTolerance diffingMethodTolerance ;
51
+ private RequestConfig requestConfig ;
50
52
51
53
public Builder (RemoteWebDriver driver , String username , String accessKey ) {
52
54
this (driver , username , accessKey , resolveEndpoint ());
@@ -108,14 +110,20 @@ public Builder withDiffingMethodTolerance(DiffingMethodTolerance diffingMethodTo
108
110
return this ;
109
111
}
110
112
113
+ public Builder withRequestConfig (RequestConfig requestConfig ) {
114
+ this .requestConfig = requestConfig ;
115
+ return this ;
116
+ }
117
+
111
118
public VisualApi build () {
112
119
VisualApi api =
113
120
new VisualApi (
114
121
driver ,
115
122
endpoint ,
116
123
username ,
117
124
accessKey ,
118
- new BuildAttributes (buildName , projectName , branchName , defaultBranchName ));
125
+ new BuildAttributes (buildName , projectName , branchName , defaultBranchName ),
126
+ requestConfig );
119
127
120
128
if (this .captureDom != null ) {
121
129
api .setCaptureDom (this .captureDom );
@@ -201,6 +209,27 @@ public VisualApi(
201
209
String username ,
202
210
String accessKey ,
203
211
BuildAttributes buildAttributes ) {
212
+ this (driver , url , username , accessKey , buildAttributes , null );
213
+ }
214
+
215
+ /**
216
+ * Creates a VisualApi instance with a custom backend URL
217
+ *
218
+ * @param driver The {@link org.openqa.selenium.WebDriver} instance where the tests should run
219
+ * with
220
+ * @param url Visual Backend URL
221
+ * @param username SauceLabs username
222
+ * @param accessKey SauceLabs access key
223
+ * @param buildAttributes like buildName, project, branch
224
+ * @param requestConfig RequestConfig object to override proxy / request settings for the client.
225
+ */
226
+ public VisualApi (
227
+ RemoteWebDriver driver ,
228
+ String url ,
229
+ String username ,
230
+ String accessKey ,
231
+ BuildAttributes buildAttributes ,
232
+ RequestConfig requestConfig ) {
204
233
if (username == null
205
234
|| accessKey == null
206
235
|| username .trim ().isEmpty ()
@@ -209,7 +238,7 @@ public VisualApi(
209
238
"Invalid SauceLabs credentials. "
210
239
+ "Please check your SauceLabs username and access key at https://app.saucelabs.com/user-settings" );
211
240
}
212
- this .client = new GraphQLClient (url , username , accessKey );
241
+ this .client = new GraphQLClient (url , username , accessKey , requestConfig );
213
242
this .sessionId = driver .getSessionId ().toString ();
214
243
String jobIdString = (String ) driver .getCapabilities ().getCapability ("jobUuid" );
215
244
this .jobId = jobIdString == null ? sessionId : jobIdString ;
@@ -226,6 +255,18 @@ public VisualApi(
226
255
String url ,
227
256
String username ,
228
257
String accessKey ) {
258
+ this (jobId , driver , build , sessionMetadataBlob , url , username , accessKey , null );
259
+ }
260
+
261
+ VisualApi (
262
+ String jobId ,
263
+ RemoteWebDriver driver ,
264
+ VisualBuild build ,
265
+ String sessionMetadataBlob ,
266
+ String url ,
267
+ String username ,
268
+ String accessKey ,
269
+ RequestConfig requestConfig ) {
229
270
if (username == null
230
271
|| accessKey == null
231
272
|| username .trim ().isEmpty ()
@@ -238,7 +279,7 @@ public VisualApi(
238
279
this .jobId = jobId ;
239
280
this .sessionId = driver .getSessionId ().toString ();
240
281
this .driver = driver ;
241
- this .client = new GraphQLClient (url , username , accessKey );
282
+ this .client = new GraphQLClient (url , username , accessKey , requestConfig );
242
283
this .sessionMetadataBlob = sessionMetadataBlob ;
243
284
}
244
285
0 commit comments