HomeWeb Testing Configure a Proxy Configure a Proxy Configure proxy servers for webmate tests when the application under test requires controlled network routing.
Multiple types of proxy servers are supported in webmate, such as unauthenticated proxies and authenticated proxies via username/password or NTLM authentication.
Credentials You can also use webmate as a proxy.
The following credentials, the proxy host and port are always required. The user and password are only required for username/password authentication with the proxy and user domain and password are required for NTLM authentication.
1
2
3
4
5
6
7
String PROXY_HOST = "localhost" ;
int PROXY_PORT = 3128;
String PROXY_USER = "proxyuser" ;
String PROXY_PASSWORD = "proxypass" ;
String PROXY_USER_DOMAIN = "userdomain" ;
This feature is not implemented in the TypeScript SDK yet!
Basic setup To use a proxy, you have to use a HttpClientBuilder and specify the host and port.
If the proxy does not need authentication, this is all you need to do.
1
2
3
4
HttpClientBuilder builder = HttpClientBuilder.create ();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy (proxy);
WebmateAPISession apiSession = new WebmateAPISession(authInfo, env, builder);
Incomplete: Not all snippets available in this language yet! Coming soon!
All code:
1
2
3
4
5
6
7
8
9
10
11
12
String PROXY_HOST = "localhost" ;
int PROXY_PORT = 3128;
String PROXY_USER = "proxyuser" ;
String PROXY_PASSWORD = "proxypass" ;
String PROXY_USER_DOMAIN = "userdomain" ;
HttpClientBuilder builder = HttpClientBuilder.create ();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy (proxy);
WebmateAPISession apiSession = new WebmateAPISession(authInfo, env, builder);
This feature is not implemented in the TypeScript SDK yet!
Authenticated proxy To use a proxy with authentication you also have to provide a CredentialsProvider and set it as provider for the builder
1
2
CredentialsProvider credsProvider = new BasicCredentialsProvider();
builder.setDefaultCredentialsProvider (credsProvider);
This feature is not implemented in the TypeScript SDK yet!
Username + password authentication proxy To use a proxy with username/password authentication you have to provide the credentials.
1
credsProvider.setCredentials (new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));
This feature is not implemented in the TypeScript SDK yet!
All code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
String PROXY_HOST = "localhost" ;
int PROXY_PORT = 3128;
String PROXY_USER = "proxyuser" ;
String PROXY_PASSWORD = "proxypass" ;
String PROXY_USER_DOMAIN = "userdomain" ;
HttpClientBuilder builder = HttpClientBuilder.create ();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy (proxy);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials (new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));
builder.setDefaultCredentialsProvider (credsProvider);
WebmateAPISession apiSession = new WebmateAPISession(authInfo, env, builder);
This feature is not implemented in the TypeScript SDK yet!
NTLM authentication proxy To use a proxy with NTLM authentication, you have to provide the credentials, which is more complex than password authentication.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
WebmateEnvironment webmateEnv = WebmateEnvironment.create ()
URI apiUrl = webmateEnv.baseURI ;
String workstation;
Map< String, String> env = System.getenv ();
if (env.containsKey ("COMPUTERNAME" )) {
workstation = env.get ("COMPUTERNAME" );
} else if (env.containsKey ("HOSTNAME" )) {
workstation = env.get ("HOSTNAME" );
} else {
try {
workstation = InetAddress.getLocalHost ().getHostName ();
}
catch (UnknownHostException ex) {
workstation = "Unknown" ;
}
}
credsProvider.setCredentials (new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, proxyPassword, workstation, proxyUserDomain));
if (apiUrl.getUserInfo () != null && ! apiUrl.getUserInfo ().isEmpty ()) {
credsProvider.setCredentials (new AuthScope(apiUrl.getHost (), apiUrl.getPort () > 0 ? apiUrl.getPort () : 443),
new UsernamePasswordCredentials(apiUrl.getUserInfo ()));
}
All code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
String PROXY_HOST = "localhost" ;
int PROXY_PORT = 3128;
String PROXY_USER = "proxyuser" ;
String PROXY_PASSWORD = "proxypass" ;
String PROXY_USER_DOMAIN = "userdomain" ;
HttpClientBuilder builder = HttpClientBuilder.create ();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy (proxy);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
WebmateEnvironment webmateEnv = WebmateEnvironment.create ()
URI apiUrl = webmateEnv.baseURI ;
String workstation;
Map< String, String> env = System.getenv ();
if (env.containsKey ("COMPUTERNAME" )) {
workstation = env.get ("COMPUTERNAME" );
} else if (env.containsKey ("HOSTNAME" )) {
workstation = env.get ("HOSTNAME" );
} else {
try {
workstation = InetAddress.getLocalHost ().getHostName ();
}
catch (UnknownHostException ex) {
workstation = "Unknown" ;
}
}
credsProvider.setCredentials (new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, proxyPassword, workstation, proxyUserDomain));
if (apiUrl.getUserInfo () != null && ! apiUrl.getUserInfo ().isEmpty ()) {
credsProvider.setCredentials (new AuthScope(apiUrl.getHost (), apiUrl.getPort () > 0 ? apiUrl.getPort () : 443),
new UsernamePasswordCredentials(apiUrl.getUserInfo ()));
}
builder.setDefaultCredentialsProvider (credsProvider);
WebmateAPISession apiSession = new WebmateAPISession(authInfo, env, builder);
This feature is not implemented in the TypeScript SDK yet!
Last update on 20 August 2020
4 min read