Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlUnitDriver: enable/disable Basic Authentication?

The answers to this question show how to enable Basic Auth with HtmlUnitDriver. However, how can I disable it again?

Note: the accepted answer to this question is correct, however, due to a bug it does not currently work.

like image 580
Christian Neverdal Avatar asked Jun 06 '26 02:06

Christian Neverdal


1 Answers

You can use a variant of .addCredentials():

WebDriver driver = new HtmlUnitDriver() {
    protected WebClient modifyWebClient(WebClient client) {
        DefaultCredentialsProvider creds = new DefaultCredentialsProvider();

        creds.addCredentials(username, password, hostname, port, realm);

        client.setCredentialsProvider(creds);
        return client;
    }
};
like image 160
Ahmed Ashour Avatar answered Jun 08 '26 00:06

Ahmed Ashour