Saturday, September 16, 2017

First Selenium Webdriver Script Using HtmlUnitDriver Driver


In this tutorial, I will give a small explanation about the HtmlUnitDriver Web Driver, and one more it will not load page in web browser. The test is executed the same way as in any other browser but the user would not be able to see any browser. Thus it executes the test script in GUI less (Headless) mode.

Before starting with programming you need to download the HtmlUnitDriver driver. Driver file you will get it from the selenium official website ( http://www.seleniumhq.org/ ).

Following source code is use to run the script using HtmlUnitDriver Driver:

package demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class SeleniumDemo {

    // variable name
    public static WebDriver driver;

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("Launching the HtmlUnitDriver driver  ");

        // Instantiate the HtmlUnitDriver driver
        driver = new HtmlUnitDriver();

        // set the browser URL in get() to load the webpage
        driver.get("https://www.google.com");
        System.exit(0);

    }

}

To run and execute the code in Eclipse IDE, you need to follow the below step:
On Eclipse's menu bar, click Run > Run.


Note : When you are running script using HtmlUnitDriver driver, that time it will not launch browser. Code will be executed in the background and you can check your code status in Eclipse console depending upon you checkpoints. 


No comments:

Post a Comment