Headless browsers
Cross browser testing for PhantomJS browser
Cross browser testing for HTMLUnit browser
What Is Headless Browser?
A headless browser is a web-browser without a graphical user interface.
A browser, which does not have any GUI it means which runs in the background
Headless browser is used to simulate programs even though there is no browser installed on your local system
Advantages Of Using Headless Browsers
Headless Browsers are Faster than Real Browsers
Running regression scripts take lots of time. With headless browsers, we could save time.
Run tests on machine without display
Disadvantages Of Using Headless Browsers
Debugging is a bit difficult using headless browsers. Here browser is not visible, the only way is to capture a screenshot.
Examples of Headless Drivers
HtmlUnit
PhantomJS
ZombieJS
Splash
Firefox Headless Mode
Headless Chrome
HTMLUnit :
HTMLUnitDriver is the most light weight and fastest implementation headless browser for of WebDriver.
It is based on HtmlUnit
Since it is not using any GUI to test, your tests will run in background without any visual interruption
Code:
We need to add jar files of HTMLUnit driver for project
@Test
public void htmlUnitBrowser() throws InterruptedException
{
WebDriver driver = new HtmlUnitDriver();
driver.get( "http://ankpro.com/");
Thread.sleep(2000);
driver.quit();
}
PhantomJS :
PhantomJS is a headless browser with JavaScript API.
PhantomJSDriver is one of the drivers of Selenium WebDriver.
Code:
We need to add PhantomJs jar files to project
[TestMethod]
public void LunchPhantamJSBrowser()
{
IWebDriver driver = new PhantomJSDriver();
driver.Url = "http://ankpro.com/";
string s=driver.FindElement(By.ClassName("jumbotron")).Text;
Console.WriteLine(s);
driver.Quit();
}
Possible Interview Questions on headless browsers :
What is headless browsers
Why we need to do cross browser testing in headless browser
What are the pros and cons of headless browsers
How to do cross browser testing for PhantomJS browser
How to do cross browser testing for HTMLUnit browser
En esta página del sitio puede ver el video en línea Selenium with Java 54 - Headless browsers testing using Phantom Js and Html unit de Duración hora minuto segunda en buena calidad , que subió el usuario Ankpro Training 18 septiembre 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 869 veces y le gustó 3 a los espectadores. Disfruta viendo!