Selenium Beginner 13 – How to use HtmlUnit Driver

Notes:

Pre-requisites – Selenium jars should be added to the project.
This is covered in the earlier session on this series.
Selenium Beginner 5 – How to write first Selenium script (java) – 5 Easy Steps

Today we will learn :

1. What is HtmlUnit Driver

2. How to run test with HtmlUnit Driver

HtmlUnitDriver driver = new HtmlUnitDriver();
driver.get(“http://seleniumhq.org/”);

3. How to emulate other browsers

HtmlUnitDriver driver = new HtmlUnitDriver ( BrowserVersion.CHROME );


Helpful Tips:

How to confirm and validate that your test ran on some specific browser

WebClient webClient = (WebClient) get(driver, “webClient”);

private static Object get(Object object, String field) throws Exception {
Field f = object.getClass().getDeclaredField(field);
f.setAccessible(true);
return f.get(object);
}

 


Interview Section:

Q. What is HtmlUnit Driver technically in Selenium library.


References:
HtmlUnit Browserhttps://en.wikipedia.org/wiki/HtmlUnit
HtmlUnit Driverhttps://github.com/SeleniumHQ/selenium/wiki/HtmlUnitDriver

HtmlUnitDriver documentationhttp://seleniumhq.github.io/htmlunit-driver/org/openqa/selenium/htmlunit/HtmlUnitDriver.html#HtmlUnitDriver-com.gargoylesoftware.htmlunit.BrowserVersion-

Webdriver documentationhttp://seleniumhq.github.io/selenium/docs/api/java/


Selenium YouTube Playlist


Send me your comments and feedback

%d bloggers like this: