Proxy configuration for HtmlUnitDriver

3,273 views
Skip to first unread message

Guilherme Garnier

unread,
Aug 11, 2010, 8:40:26 AM8/11/10
to webdriver
Hello all. I´m having some trouble trying to configure proxy for
WebDriver. InternetExplorerDriver doesn´t need proxy configuration,
because it gets from Windows. For FirefoxDriver the following
configuration works fine:

private WebDriver createFirefoxDriver() {
FirefoxProfile firefoxProfile = new FirefoxProfile();

firefoxProfile.setPreference("network.proxy.type", 1);
firefoxProfile.setPreference("network.proxy.http", PROXY_HOST);
firefoxProfile.setPreference("network.proxy.http_port",
PROXY_PORT);
firefoxProfile.setPreference("network.proxy.ssl", PROXY_HOST);
firefoxProfile.setPreference("network.proxy.ssl_port",
PROXY_PORT);
firefoxProfile.setPreference("network.proxy.no_proxies_on", "");

return new FirefoxDriver(firefoxProfile);
}

But for HtmlUnitDriver I can´t make it work. I´m trying the following:

private WebDriver createHtmlUnitDriver() {
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver() {
@Override
protected WebClient modifyWebClient(WebClient client) {
client.setProxyConfig(new ProxyConfig(PROXY_HOST,
PROXY_PORT));

DefaultCredentialsProvider credentialsProvider = new
DefaultCredentialsProvider();
credentialsProvider.addCredentials(PROXY_USERNAME,
PROXY_PASSWORD);
credentialsProvider.addProxyCredentials(PROXY_USERNAME,
PROXY_PASSWORD, PROXY_HOST, PROXY_PORT);
client.setCredentialsProvider(credentialsProvider);

return client;
}
};

htmlUnitDriver.setProxy(PROXY_HOST, PROXY_PORT);
htmlUnitDriver.setJavascriptEnabled(true);

return htmlUnitDriver;
}

I get an
org.apache.commons.httpclient.auth.InvalidCredentialsException. Can
anyone help me? Thanks

Eran M.

unread,
Aug 16, 2010, 9:01:32 AM8/16/10
to webd...@googlegroups.com
Hi,

First, it seems that the call to setProxy is redundant, given that you're setting it yourself just before.
You don't specify where you get the exception - since I'm guessing here, I'd say that the proxy rejects the credentials and you should sniff the traffic to see if HtmlUnit sends it differently (that'd be better answered by the HtmlUnit team).
If you have a proxy auto-configuration you can provide, you could call setAutoProxy on the HtmlUnitDriver to set it.

Eran


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Guilherme Garnier

unread,
Aug 17, 2010, 12:34:57 PM8/17/10
to webdriver
Hello Eran, thanks for your answer. For me HtmlUnitDriver doesn´t have
a setAutoProxy method. I´m using the latest version from Maven
repository (0.9.7376)

--
Guilherme Garnier
http://blog.guilhermegarnier.com/

On Aug 16, 10:01 am, "Eran M." <eran....@gmail.com> wrote:
> Hi,
>
> First, it seems that the call to setProxy is redundant, given that you're
> setting it yourself just before.
> You don't specify where you get the exception - since I'm guessing here, I'd
> say that the proxy rejects the credentials and you should sniff the traffic
> to see if HtmlUnit sends it differently (that'd be better answered by the
> HtmlUnit team).
> If you have a proxy auto-configuration you can provide, you could call
> setAutoProxy on the HtmlUnitDriver to set it.
>
> Eran
>
> > webdriver+...@googlegroups.com<webdriver%2Bunsu...@googlegroups.com>
> > .

Daniel Wagner-Hall

unread,
Aug 17, 2010, 3:39:48 PM8/17/10
to webd...@googlegroups.com
That is an incredibly old release. WebDriver has become Selenium 2 -
links to the artifacts can be found on
http://seleniumhq.wordpress.com/2010/07/30/how-to-use-selenium-2-with-maven/

> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Guilherme Garnier

unread,
Aug 18, 2010, 2:44:33 PM8/18/10
to webdriver
I was using the latest version I found on http://mvnrepository.com.
Now I´m using this configuration on Maven:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.0a5</version>
</dependency>

setAutoProxy didn´t work for me, but this configuration worked:

private static WebDriver createHtmlUnitWebDriver() {
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver() {
@Override
protected WebClient modifyWebClient(WebClient client) {
DefaultCredentialsProvider credentialsProvider = new
DefaultCredentialsProvider();

credentialsProvider.addNTLMProxyCredentials(PROXY_USERNAME,
PROXY_PASSWORD, PROXY_HOST, PROXY_PORT, CLIENT_HOST, CLIENT_DOMAIN);
client.setCredentialsProvider(credentialsProvider);

return client;
}
};
htmlUnitDriver.setProxy(PROXY_HOST, PROXY_PORT);
return htmlUnitDriver;
}

Thanks everyone for the help.

--
Guilherme Garnier
http://blog.guilhermegarnier.com

On Aug 17, 4:39 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> That is an incredibly old release.  WebDriver has become Selenium 2 -
> links to the artifacts can be found onhttp://seleniumhq.wordpress.com/2010/07/30/how-to-use-selenium-2-with...
Reply all
Reply to author
Forward
0 new messages