Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  1. Extremely slow (I think the chrome/FF remote drivers are faster than it)
  2. 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?

like image 912
Guy Avatar asked Jun 19 '11 12:06

Guy


2 Answers

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).

like image 91
lukeis Avatar answered Sep 25 '22 21:09

lukeis


you can also enable javascript as follows.

((HtmlUnitDriver) driver).setJavascriptEnabled(true);

like image 23
user1307037 Avatar answered Sep 24 '22 21:09

user1307037