Skip to content

Commit 1e9c96d

Browse files
authored
Fix a few Windows-specific issues (#336)
1 parent bb3707b commit 1e9c96d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/main/java/com/nordstrom/automation/selenium/core/GridUtility.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@
2727
import java.util.ServiceConfigurationError;
2828
import java.util.ServiceLoader;
2929
import java.util.concurrent.TimeoutException;
30+
31+
import org.apache.http.HttpEntity;
3032
import org.apache.http.HttpHost;
3133
import org.apache.http.HttpResponse;
3234
import org.apache.http.HttpStatus;
3335
import org.apache.http.client.HttpClient;
36+
import org.apache.http.client.config.RequestConfig;
3437
import org.apache.http.client.methods.HttpGet;
3538
import org.apache.http.client.methods.HttpPost;
3639
import org.apache.http.client.utils.URIUtils;
40+
import org.apache.http.entity.BufferedHttpEntity;
3741
import org.apache.http.entity.ContentType;
3842
import org.apache.http.entity.StringEntity;
43+
import org.apache.http.impl.client.CloseableHttpClient;
3944
import org.apache.http.impl.client.HttpClientBuilder;
4045
import org.openqa.selenium.Capabilities;
4146
import org.openqa.selenium.MutableCapabilities;
@@ -93,9 +98,22 @@ public static boolean isHostActive(final URL hostUrl, final String... pathAndPar
9398
*/
9499
public static HttpResponse getHttpResponse(final URL hostUrl, final String... pathAndParams) throws IOException {
95100
Objects.requireNonNull(hostUrl, "[hostUrl] must be non-null");
96-
HttpClient client = HttpClientBuilder.create().build();
101+
97102
URI uri = UriUtils.makeBasicURI(hostUrl.getProtocol(), hostUrl.getHost(), hostUrl.getPort(), pathAndParams);
98-
return client.execute(extractHost(hostUrl), new HttpGet(uri.toURL().toExternalForm()));
103+
104+
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000)
105+
.setConnectionRequestTimeout(2000).setSocketTimeout(5000).build();
106+
CloseableHttpClient client = HttpClientBuilder.create().disableAutomaticRetries()
107+
.setDefaultRequestConfig(requestConfig).build();
108+
109+
HttpGet request = new HttpGet(uri.toString());
110+
HttpResponse response = client.execute(extractHost(hostUrl), request);
111+
HttpEntity entity = response.getEntity();
112+
if (entity != null && entity.isStreaming()) {
113+
response.setEntity(new BufferedHttpEntity(entity));
114+
}
115+
116+
return response;
99117
}
100118

101119
/**

src/main/java/com/nordstrom/automation/selenium/model/Page.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import org.apache.commons.lang3.ArrayUtils;
88
import org.openqa.selenium.SearchContext;
9-
import org.openqa.selenium.UnsupportedCommandException;
109
import org.openqa.selenium.WebDriver;
10+
import org.openqa.selenium.WebDriverException;
1111

1212
import com.nordstrom.automation.selenium.annotations.InitialPage;
1313
import com.nordstrom.automation.selenium.annotations.PageUrl;
@@ -96,7 +96,7 @@ protected SearchContext switchToContext() {
9696
}
9797
try {
9898
driver.switchTo().defaultContent();
99-
} catch(UnsupportedCommandException eaten) {
99+
} catch(WebDriverException eaten) {
100100
// unsupported on native platforms
101101
}
102102
return this;
@@ -232,7 +232,7 @@ public SearchContext getWrappedContext() {
232232
public SearchContext refreshContext(final long expiration) {
233233
try {
234234
driver.switchTo().defaultContent();
235-
} catch(UnsupportedCommandException eaten) {
235+
} catch(WebDriverException eaten) {
236236
// unsupported on native platforms
237237
}
238238
return this;

0 commit comments

Comments
 (0)