How stable and fast is HtmlUnit
I'm upgrading from selenium-1 to selenium-2 and trying out the new HtmlUnit driver. I've tried a few basic tests on it (open a page, get_text,..) and it seems
- Extremely slow (I think the chrome/FF remote drivers are faster than it)
- Extremely un-stable (opening yahoo.com using HTMLUNIT and HTMLUNITWITHJS both resulted in errors)
I'd be very happy to hear your impression of it. I hope you'll find I'm wrong (I can live without (1) speed but (2) stability is critical)? is there a speed comparison of HtmlUnit vs the selenium drivers?
In my experience HtmlUnit is much faster than Firefox, noticeably faster than chrome (which is the fastest full browser with selenium 2.0rc2). HtmlUnit does not need to download external resources and if you use it without a BrowserVersion then javascript is disabled by default:
WebDriver driver = new HtmlUnitDriver();
But if you pass in a browser version then it is enabled, but runs slower since it will download the javascript files:
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
That being said, the javascript is not up to par with real browsers. Google's and Yahoo's homepage don't work properly. Modern browsers are tolerant to certain javascript errors (exploits / hacks), while HtmlUnit is not.
I usually use HtmlUnitDriver on pages / flows that don't require heavy javascript and I just need to verify elements / data existing on pages (that are not dynamically loaded).
you can also enable javascript as follows.
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
精彩评论