MainMenu

Home Java Overview Maven Tutorials

Wednesday 25 October 2017

HeadLess Browser testing in Selenium


Hello friends,

In this article we will discuss about headless or Ghost browser :

For Video :- Click Here



What is headless browser ?

Browser which is not visible to user is known as headless browser.
They are also know as Ghost browser.
in terms of selenium, Browser which will be controlled by selenium but will not be visible to user is known as headless browser testing.


Different kind of headless browser

In selenium we have following headless browser :

1).HtmlUnit
2).PhantomJS
3).Ghost
4).ZombieJS
5).Watir-webdriver
6).Jbrowser


Lets Talk about HtmlUnitDriver
1). The fastest browser among all the browsers
2). Excellent JavaScript support
3).Support for the HTTPS and HTTP protocols
4).Support for HTML responses
5).Support for cookies
5). Proxy server support
7). Support for basic and NTLM authentication
8).Support for submit methods GET and POST
9). Ability to customize the request headers being sent to the server
10). Ability to determine whether failing responses from the server should throw exceptions or should be returned as pages of the appropriate type


Cons of HtmlUnitDriver
1).It cannot emulate other browsers JavaScript behavior
2).Many times it get for complicated scripts

How to configure HtmlUnitDriver in Selenium Project

First of all download the jar files of HTMLUnitDriver by using below links :=

Download from website : Click here
download from google driver : Click here

Now create the Java Project & add this Jar file in your project 

 


Code

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class GhostDR
{
WebDriver driver;
@BeforeTest
public void g()
{
driver = new HtmlUnitDriver();
//System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\chromedriver.exe");
//driver = new ChromeDriver();
driver.navigate().to("http://www.way2testing.com");
}
@Test
public void h()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
}
}




output :

Best Online Software Testing Tutorial: Software Testing
PASSED: h


Another good headless browser is phantomJS
PhantomJS is a headless browser with Javascript API.
It is also a favorite browser for most of Automation tester.
The main thing is that it is fast & able to handle large & complicated Script.
Download Phantom JS Browser below :
Download from Maven Website : Click Here to Download PhantomJS Driver
Click here to Download phantomJS Jar

Click here to download from Google Drive
Configure the project for PhantomJSDriver :-
You need to follow few steps :-
1). File file = new File("local system path/bin/phantomjs.exe")

2).set the path of PhantomJSDriver
System.setProperty("phantomjs.binary.path", file.getAbsolutePath())

3).WebDriver driver = new PhantomJSDriver();



Code

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class PISOFT
{
WebDriver driver;
@BeforeTest
public void g()
{
File file = new File("D:\\Selenium\\Complete selenium\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
driver = new PhantomJSDriver();
//driver = new HtmlUnitDriver();
//System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\chromedriver.exe");
//driver = new ChromeDriver();
driver.navigate().to("http://www.way2testing.com");
}
@Test
public void h()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
}
}


output :

Best Online Software Testing Tutorial: Software Testing
PASSED: h







Tags :-


Headless browser testing in selenium


Selenium testing with PhantonJS browser


Selenium testing with Ghost browser


Selenium testing with HTMLUnitDriver


How to Download and Configure PhantomJSDriver


How to Download and configure HTMLUnitDriver




No comments:

Post a Comment