1. What is Headless Browser?
Executing the tests on background without viewing the execution on any Browser that you desired to.
2. How Headless Browser helps QA?
Helps in the executing the tests in a Non-UI mode i.e., Selenium Headless Browser
3. Is Headless Brower supports widely available Browsers like Chrome or Firefox etc?
Latest versions of SeleniumWebDriver 3 & 4, supports headless versions of real browsers like Chrome, Firefox, and Edge
4. Limitations of Headless Browser?
1. Page load issues
2. Sync
3. Tracing the defects of the application
4. UI validations like page align, background colors etc
5. How Java helps in Headless Browser?
HtmlUnitDriver is a Java based implementation of Selenium WebDriver based on HtmlUnit, without a GUI.
6. Headless Browser Maven Dependency!!
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
NOTE: Version may vary based on the selenium version you are using.
7. Ways to implement in the Selenium Code using Java!
1. Using HtmlUnitDriver, which is the default usage. Refer the Example 1.
2. Using widely used browsers. Refer the Example 2.
Example 1: Using the HtmlUnitDriver()
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class headlessBrowserDemo {
public static void main(String[] args) {
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver();
htmlUnitDriver.get("https://google.com/");
System.out.println("Title of the page is = " + htmlUnitDriver.getTitle());
}
}
Example 2: Using the ChromeDriver()
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class headlessBrowserDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
WebDriver driver=new ChromeDriver(options);
driver.get("https://google.com/");
System.out.println("Title of the page is = " + driver.getTitle());
}
}
No comments:
Post a Comment