jwebunit set a proxy for webtester webclient

480 Views Asked by At

I have a problem in setting a proxy config in webtester. Before, with htmlunit 2.11 jar I was using the following code:

HtmlUnitTestingEngineImpl h = (HtmlUnitTestingEngineImpl) wt.getTestingEngine();
ProxyConfig proxyConfig = new ProxyConfig(ip, 4128);
h.getWebClient().setProxyConfig(proxyConfig);

After updating jwebunit libraries (i.e. htmlunit 2.13, httpclient4.3.1 etc.) the setProxyConfig method isn't supported in WebClient. It seems the only way to set proxy in WebClient is in the constructor. Now, How can I set a proxy configuration for a jwebunit WebTester? Thanks

1

There are 1 best solutions below

0
On

You can use

webTester.getTestContext().setProxyAuthorization(null, null, ip, 4128);

buy pay attention to set the proxyauthorization BEFORE webtester.beginAt(..)

In the beginAt method happens the webclient init with proxy parameter. After beginAt the webclient is reused so the first code (setProxyAuthorization) can't affect the webclient.