diff --git a/pom.xml b/pom.xml index bffeb93..3ad873d 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ com.xceptance xlt - 4.10.1 + 5.2.1 diff --git a/src/main/java/xltutil/proxy/ProxyHttpClient.java b/src/main/java/xltutil/proxy/ProxyHttpClient.java index 4ab59b2..698ecd9 100644 --- a/src/main/java/xltutil/proxy/ProxyHttpClient.java +++ b/src/main/java/xltutil/proxy/ProxyHttpClient.java @@ -2,21 +2,34 @@ import java.net.URL; -import org.apache.http.client.HttpClient; -import org.openqa.selenium.remote.internal.ApacheHttpClient; +import org.openqa.selenium.remote.http.HttpClient; +import org.openqa.selenium.remote.http.HttpClient.Builder; +import org.openqa.selenium.remote.internal.OkHttpClient; public class ProxyHttpClient implements org.openqa.selenium.remote.http.HttpClient.Factory { - private final HttpClient httpClient; + private final OkHttpClient okHttpClient; - public ProxyHttpClient(HttpClient httpClient) + public ProxyHttpClient(OkHttpClient okHttpClient) { - this.httpClient = httpClient; + this.okHttpClient = okHttpClient; } @Override public org.openqa.selenium.remote.http.HttpClient createClient(URL url) { - return new ApacheHttpClient(httpClient, url); + return (HttpClient) okHttpClient; + } + + @Override + public Builder builder() + { + throw new UnsupportedOperationException(); + } + + @Override + public void cleanupIdleClients() + { + } } diff --git a/src/main/java/xltutil/runner/AnnotationRunner.java b/src/main/java/xltutil/runner/AnnotationRunner.java index 91fdaaa..4b99de2 100644 --- a/src/main/java/xltutil/runner/AnnotationRunner.java +++ b/src/main/java/xltutil/runner/AnnotationRunner.java @@ -33,7 +33,6 @@ import org.openqa.selenium.firefox.GeckoDriverService; import org.openqa.selenium.ie.InternetExplorerDriverService; import org.openqa.selenium.opera.OperaDriverService; -import org.openqa.selenium.phantomjs.PhantomJSDriverService; import com.xceptance.xlt.api.data.DataSetProvider; import com.xceptance.xlt.api.data.DataSetProviderException; @@ -262,10 +261,7 @@ public AnnotationRunner(final Class testCaseClass, final String testCaseName, { System.setProperty(OperaDriverService.OPERA_DRIVER_EXE_PROPERTY, operaDriverPath); } - if (!StringUtils.isEmpty(phantomJSDriverPath)) - { - System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJSDriverPath); - } + boolean foundTargetsAnnotation = false; // get test specific browser definitions (aka browser tag see browser.properties) diff --git a/src/main/java/xltutil/runner/helper/AnnotationRunnerHelper.java b/src/main/java/xltutil/runner/helper/AnnotationRunnerHelper.java index 0e62f8f..1b78eec 100644 --- a/src/main/java/xltutil/runner/helper/AnnotationRunnerHelper.java +++ b/src/main/java/xltutil/runner/helper/AnnotationRunnerHelper.java @@ -1,6 +1,8 @@ package xltutil.runner.helper; +import java.io.IOException; import java.lang.annotation.Annotation; +import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -10,15 +12,13 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; import org.openqa.selenium.Dimension; import org.openqa.selenium.Proxy; import org.openqa.selenium.UnsupportedCommandException; @@ -34,13 +34,13 @@ import org.openqa.selenium.ie.InternetExplorerOptions; import org.openqa.selenium.opera.OperaDriver; import org.openqa.selenium.opera.OperaOptions; -import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.CommandInfo; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.remote.internal.OkHttpClient; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.safari.SafariOptions; @@ -49,6 +49,10 @@ import com.xceptance.xlt.api.webdriver.XltFirefoxDriver; import com.xceptance.xlt.engine.SessionImpl; +import okhttp3.Authenticator; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Route; import xltutil.annotation.TestTargets; import xltutil.dto.BrowserConfigurationDto; import xltutil.dto.ProxyConfigurationDto; @@ -137,17 +141,34 @@ public static HttpCommandExecutor createGridExecutor(final ProxyConfigurationDto basicCredentialsProvider.setCredentials(gridAuth, gridCredentials); } + Authenticator proxyAuthenticator = new Authenticator() + { + @Override + public Request authenticate(Route route, Response response) throws IOException + { + AuthScope scope = new AuthScope(route.socketAddress().getHostName(), route.socketAddress().getPort()); + return response.request().newBuilder() + .header("Proxy-Authorization", basicCredentialsProvider.getCredentials(scope).toString()) + .build(); + } + }; + // now create a http client, set the custom proxy and inject the credentials - final HttpClientBuilder clientBuilder = HttpClientBuilder.create(); - clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider); + final okhttp3.OkHttpClient.Builder clientBuilder = new okhttp3.OkHttpClient.Builder() + .connectTimeout(60, TimeUnit.SECONDS) + .writeTimeout(60, TimeUnit.SECONDS) + .readTimeout(60, TimeUnit.SECONDS); if (proxyConfig != null) - clientBuilder.setProxy(new HttpHost(proxyConfig.getHost(), Integer.valueOf(proxyConfig.getPort()))); - final CloseableHttpClient httpClient = clientBuilder.build(); + { + clientBuilder.proxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(proxyConfig.getHost(), Integer.valueOf(proxyConfig.getPort())))) + .proxyAuthenticator(proxyAuthenticator); + + } final Map additionalCommands = new HashMap(); // just a dummy // this command executor will do the credential magic for us. both proxy and target site credentials - return new HttpCommandExecutor(additionalCommands, gridUrl, new ProxyHttpClient(httpClient)); + return new HttpCommandExecutor(additionalCommands, gridUrl, new ProxyHttpClient(new OkHttpClient(clientBuilder.build(), gridUrl))); } @@ -247,10 +268,14 @@ public static WebDriver createWebdriver(final BrowserConfigurationDto config, fi final ChromeOptions options = new ChromeOptions(); // This is a workaround for a changed Selenium behavior - // Since device emulation is not part of the "standard" it now has to be considered as experimental option. - // The capability class already sorts the different configurations in different maps (one for capabilities and one for - // experimental capabilities). The experimental options are held internal within a map of the capability map and - // are accessible with key "goog:chromeOptions" (constant ChromeOptions.CAPABILITY). So all we have to do is to copy the + // Since device emulation is not part of the "standard" it now has to be considered as experimental + // option. + // The capability class already sorts the different configurations in different maps (one for + // capabilities and one for + // experimental capabilities). The experimental options are held internal within a map of the capability + // map and + // are accessible with key "goog:chromeOptions" (constant ChromeOptions.CAPABILITY). So all we have to + // do is to copy the // keys and values of that special map and set it as experimental option inside ChromeOptions. Map experimentalOptions = null; try @@ -331,10 +356,6 @@ else if (BrowserType.EDGE.equals(browserName)) return new EdgeDriver(options); } - else if (BrowserType.PHANTOMJS.equals(browserName)) - { - return new PhantomJSDriver(capabilities); - } } else {