Selenium with Java 54 - Headless browsers testing using Phantom Js and Html unit

Опубликовано: 18 Сентябрь 2019
на канале: Ankpro Training
869
3

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


Смотрите видео Selenium with Java 54 - Headless browsers testing using Phantom Js and Html unit онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Ankpro Training 18 Сентябрь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 86 раз и оно понравилось людям.