I am trying to use the Selenium HtmlUnit driver in C# tests. As far as I know, the only way to use the HtmlUnit driver in C# is through Selenium server and the RemoteWebDriver:
var driver = new OpenQA.Selenium.Remote.RemoteWebDriver(
OpenQA.Selenium.Remote.DesiredCapabilities.HtmlUnitWithJavaScript());
However, I also need to use NTLM authentication. Using the non-remote driver in Java, it can apparently be configured like this:
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;
}
}
(Source: https://groups.google.com/forum/#!topic/webdriver/ktIWIs5m0mQ)
But this obviously does not solve my problem since I am using C#. How can I do that ? (I can use Chrome successfully, but I would like to use HtmlUnit for speed).
Thanks !
Selenium RemoteWebDriver : Difference between WebDriver and RemoteWebDriver. Selenium Webdriver is a tool used to execute automated test cases on various browsers. The object of the WebDriver is a browser. Selenium RemoteWebDriver implements the WebDriver interface to execute test cases.
Selenium RemoteWebDriver is used to execute the browser automation suite on a remote machine. In other words, RemoteWebDriver is a class that implements the WebDriver interface on the remote server. The browser driver classes like FirefoxDriver, ChromeDriver, InternetExplorerDriver, etc.
To handle the basic authentication popup, we can pass the username and password along with the web page's URL. When the login pop-up is prompted, we enter the username as “admin” and the password as “admin” and then login. Thus, the user would be successfully logged into the website.
In order to pass credentials you need to overload the modifyWebClient
of the HtmlUnitDriver
, as you saw in the discussion link1.
For the .NET developer the only way to use the HtmlUnitDriver is via the RemoteWebDriver
, and based on the discussion HtmlUnit wrapper for .NET2 the developers chose not to expose all of the HtmlUnit
driver classes:
I'm loathe to take any more dependencies in the .NET bindings... If you're dead-set on using HtmlUnit as your headless browser of choice, you can always use it via the RemoteWebDriver
Therefore you cannot use NTLM, or any other credential method, with the RemoteWebDriver.
If you were willing to do and maintain the work you could convert all the HtmlUnit code as detailed in the second link of @JasonPlutext's answer3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With