How to achieve NTLM authentication using HTMLUnitDriver?

1,271 views
Skip to first unread message

Priyaa

unread,
Aug 24, 2009, 7:50:43 AM8/24/09
to webdriver
Hi,

My application uses NTLM authentication mechanism to authenticate
the user logged in. When I use FireFox driver, the application works
fine (as the application opens with the user running the tests).
However, when I use HTMLdriver for the same, I am getting the
following error:

Aug 24, 2009 5:05:41 PM
org.apache.commons.httpclient.auth.AuthChallengeProcessor
selectAuthScheme
INFO: ntlm authentication scheme selected
Aug 24, 2009 5:05:41 PM
org.apache.commons.httpclient.HttpMethodDirector
processWWWAuthChallenge
INFO: No credentials available for NTLM <any realm>@dportalqa.com:80

Could someone please suggest a solution for this?

Thanks in advance,
Priyaa

Simon Stewart

unread,
Aug 25, 2009, 1:13:40 PM8/25/09
to webd...@googlegroups.com
When creating your instance of HtmlUnit, override the "modifyWebClient" method:

WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
// Does nothing here to be overridden.
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
creds.addNTLMCredentials("userName", "password", null, -1,
"myComputerName", "myDomain");
client.setCredentialsProvider(creds);

return client;
}
}

Regards,

Simon

Simon Stewart

unread,
Aug 25, 2009, 1:19:16 PM8/25/09
to webd...@googlegroups.com
And I've just added the answer to the FAQ:

http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions

Cheers,

Simon

Priyaa

unread,
Aug 26, 2009, 2:40:03 AM8/26/09
to webdriver
Thanks a lot for the quick response, Simon.
It was definitely helpful.

Thanks,
Priyaa
Reply all
Reply to author
Forward
0 new messages