Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

#2 update to xlt 5.2.1 #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>com.xceptance</groupId>
<artifactId>xlt</artifactId>
<version>4.10.1</version>
<version>5.2.1</version>
</dependency>
</dependencies>

Expand Down
25 changes: 19 additions & 6 deletions src/main/java/xltutil/proxy/ProxyHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{

}
}
6 changes: 1 addition & 5 deletions src/main/java/xltutil/runner/AnnotationRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
55 changes: 38 additions & 17 deletions src/main/java/xltutil/runner/helper/AnnotationRunnerHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<String, CommandInfo> additionalCommands = new HashMap<String, CommandInfo>(); // 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)));

}

Expand Down Expand Up @@ -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<String, String> experimentalOptions = null;
try
Expand Down Expand Up @@ -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
{
Expand Down