Search Here!

Sunday, June 24, 2012

Getting Started With HTMLUnitDriver: A Silent Simulator



HTMLUnitDriver
This is currently the fastest and most lightweight implementation of WebDriver. As the name suggests, this is based on HtmlUnit. HtmlUnitDriver is a class of Interface WebDriver using namespace as OpenQA.Selenium.Remote; 

HtmlUnitDriver, a pure Java driver based on HtmlUnit browser simulator (all Java-capable OS).When running, you won’t see any window opening because it doesn’t render any page like Firefox would. You can’t use it to get size or position of pages' elements
It is very fast but does not provides JavaScript yet: this feature is still a WIP. If you want to use it anyway, use  desiredCapabilities.IsJavaScriptEnabled = true;
FirefoxDriver: supports Firefox (2.x and 3.x, all OS)
InternetExplorerDriver: supports InternetExplorer (tested on IE6, 7 and 8, should work on IE5.5 and on Windows XP and Vista)
ChromeDriver: drives Google’s browser (>= 4.0, all OS)


To use HtmlUnit you need to use the RemoteWebDriver and pass in the desired capabilities for it. Beloe code will help you to run application using HTMLUnitDriver using .Net. Note that you’ll need to run the remote WebDriver server to useHtmlUnit from C#

1. There is no Class HtmlUnit  in C# (dlls for Selenium)
2.  HtmlUnit  is really fast
We can walk through in this method:
1. Install  Selenium Server and start it using java -jar selenium server path
2.  To get an instance of the HtmlUnit Driver.
IWebDriver drive = new RemoteWebDriver(DesiredCapabilities.HtmlUnit());

---------------------------------------------------
using System;
using System.Configuration;
using OpenQA.Selenium.Remote;



               public static IWebDriver WebDriver;



               var remoteServer = new Uri("http://localhost:4444/wd/hub/");
               DesiredCapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
               WebDriver = new RemoteWebDriver(remoteServer, desiredCapabilities);
               desiredCapabilities.IsJavaScriptEnabled = true;
               WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
               //go to url 
               WebDriver.Navigate().GoToUrl("http://google.co.in");


No comments:

Post a Comment