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 Browser – https://en.wikipedia.org/wiki/HtmlUnit
HtmlUnit Driver – https://github.com/SeleniumHQ/selenium/wiki/HtmlUnitDriver
HtmlUnitDriver documentation – http://seleniumhq.github.io/htmlunit-driver/org/openqa/selenium/htmlunit/HtmlUnitDriver.html#HtmlUnitDriver-com.gargoylesoftware.htmlunit.BrowserVersion-
Webdriver documentation – http://seleniumhq.github.io/selenium/docs/api/java/
Send me your comments and feedback