Friday, 8 November 2013

HTMLUnitDriver Extra cover

HTMLUnitDriver is the fastest implementation of WebDriver. It is a java based implementation of a Web Browser without a GUI. For any language binding (other than java) the Selenium Server is required to use this driver. It supports JavaScript. JavaScript engine used by the HTMLUnit (Rhino) is different from other popular browsers. Testing JavaScript using HTMLUnit differ significantly with results.

Note:
Download the latest Selenium drivers[2.35 or above];  Older versions of Selenium won't work.

Handle Transparent Proxy 

HtmlUnitDriver driver = new HtmlUnitDriver();    
driver.setProxy("xxx.xxx.xxx.xxx", port);    //  set proxy for handling Transparent Proxy
driver.setJavascriptEnabled(true);    //  enable JavaScript [this emulate IE's js by default]


Emulate popular Browser's JS

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_17);
driver.setJavascriptEnabled(true);


Emulate specific Browser's JS using Capabilities

#1
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
driver = new HtmlUnitDriver(capabilities);
#2
DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
capabilities.setVersion("24.0");
driver = new HtmlUnitDriver(capabilities); 

7 comments:

  1. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about SAP BASIS.SAP basis

    ReplyDelete
  3. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  4. Best place to learn Appium Android IOS Automation Testing Training in Chennai

    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete
  5. Can't we capture screenshots using HTMLunit driver as that of PhantomJs.
    HTMLunitdriver screenshots throws some cast exception.

    ReplyDelete