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
How to Download & Install Selenium WebDriver. Download the Selenium Java Client Driver. WebDriver can drive HTMLUnit using HtmlUnitDriver as driver server. Download JAR files for selenium-htmlunit-driver-2.48.2 With dependencies Documentation Source code.
Dan TaoDan Tao
3 Answers
To use HtmlUnit you need to use the RemoteWebDriver and pass in the desired capabilities for it.
and away you go. If you want the Firefox implementation to run use
AutomatedTesterAutomatedTester
Driver Download For Windows 10
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
JasonPlutext
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 TaoDan Tao
Not the answer you're looking for? Browse other questions tagged .netseleniumwebdriverhtmlunit-driver or ask your own question.
This is currently the fastest and most lightweight implementation of WebDriver. As the name suggests, this is based on HtmlUnit.
Pros
- Fastest implementation of WebDriver
- A pure Java solution and so it is platform independent.
- Supports Javascript
Cons
Selenium-htmlunit-driver
- Emulates other browser's JS behaviour (see below)
Javascript in the HtmlUnitDriver
None of the popular browsers uses the javascript engine used by HtmlUnit (Rhino). If you test javascript using HtmlUnit the results may differ significantly from those browsers.
When we say 'javascript' we actually mean 'javascript and the DOM'. Although the DOM is defined by the W3C each browser out there has its own quirks and differences in their implementation of the DOM and in how javascript interacts with it. HtmlUnit has an impressively complete implementation of the DOM and has good support for using javascript, but it is no different from any other browser: it has its own quirks and differences from both the W3C standard and the DOM implementations of the major browsers, despite its ability to mimic other browsers.
With WebDriver, we had to make a choice; do we enable HtmlUnit's javascript capabilities and run the risk of teams running into problems that only manifest themselves there, or do we leave javascript disabled, knowing that there are more and more sites that rely on javascript? We took the conservative approach, and by default have disabled support when we use HtmlUnit. With each release of both WebDriver and HtmlUnit, we reassess this decision: we hope to enable javascript by default on the HtmlUnit at some point.
Enabling Javascript
If you can't wait, enabling Javascript support is very easy:
or
This will cause the HtmlUnitDriver to emulate IE's Javascript handling by default.
Emulating a Specific Browser
Notwithstanding other considerations above, it is possible to get HtmlUnitDriver to emulate a specific browser. You should not really be doing this, as web-applications are better coded to be neutral of which reasonably recent browser you are using. There are two more constructors for HtmlUnitDriver that take allow us to indicate a browser to emulate. One takes a browser version directly:
Iphone Driver Download
The other uses a broader capabilities mechanism: