24

I'm using Selenium's WebDriver to run some SpecFlow tests for an ASP.NET MVC app I'm working on for self-education.

Using FirefoxDriver, ChromeDriver, etc. all take so long to run, it's actually pretty frustrating to use them (in my opinion).

I have read about an HtmlUnitDriver that is supposedly much faster than the browser-based drivers; but I can't seem to find a version in the .NET client library (only Java). Is there a .NET version out there?

Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
Dan Tao
  • 125,917
  • 54
  • 300
  • 447

3 Answers3

25

To use HtmlUnit you need to use the RemoteWebDriver and pass in the desired capabilities for it.

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit())

and away you go. If you want the Firefox implementation to run use

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript())
AutomatedTester
  • 22,188
  • 7
  • 49
  • 62
  • 1
    MUCH faster than the other drivers, and perfect for simple HTML tests. Thanks! – Dan Tao Feb 23 '11 at 21:52
  • 9
    Don't forget this means you need to start the Selenium-Server-Standalone.jar on the machine you want to run the browser – pnewhook Feb 25 '11 at 14:50
  • 2
    This approach doesn't seem to work... 13:29:08.259 INFO - WebDriver remote server: Executing: [new session: null] at U RL: /session) 13:29:08.269 INFO - WebDriver remote server: Exception: java.lang.NullPointerExc eption – Justin Apr 12 '11 at 17:29
  • Didn't work for me using Selenium 2.53.1: `The best matching driver provider org.openqa.selenium.edge.EdgeDriver can't create a new driver instance for Capabilities [{browserName=htmlunit, version=, platform=ANY}]` – Sam Oct 12 '16 at 04:17
2

The RemoteWebDriver approach is the one the Selenium devs recommend: discussion

As per that link however, if you prefer, it is easy enough invoke HtmlUnit via IKVM; that worked well for me.

I think Steve Sanderson described this first.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
0

Well, looks like the answer right now is unfortunately no. I found this on the Google Code site; a user asked:

Is this possible to transfer to C#?

...to which one of the developers responded:

Not without taking a dependency on IKVM, which is not something we are prepared to do at this time.

Oh well :(

Dan Tao
  • 125,917
  • 54
  • 300
  • 447