Headless Browser in Selenium using PhantomJS-Pros and Cons



PhantomJS is a headless web browser scriptable with JavaScript which is similar to HTMLUnitDriver. Click on this link to view the examples of the HTMLUnitDriver.

PhantomJS runs on Windows, macOS, Linux, and FreeBSD. Currently the PhantomJS development is stopped due to less support from the group.

Pros of Headless Browser:

  • Headless browser executes the scripts faster then the real browser.
  • Helps us in improves the performance execution of the scripts.
    Headless browser saves time.

Cons of Headless Browser:

  • Headless browser does not mimic the real execution of the test-cases.
  • It not possible to view the steps visually during the execution of the test-cases.

Like our Facebook Page to get frequent updates->

https://www.facebook.com/totalqa


Selenium WebDriver Code

1. Add the following dependency in the pom.xml to add the PhantomJS Library to the build path:


2. Instead of the setting the path to the Phantom JS executable. Use the WebDriverManager class ensure the following depedency is added in the maven project object model (pom.xml) file.


3. Execute the below code in eclipse and verify the results.

Conclusion

Selenium Code executed successfully without launching the Browser.

HeadLess Browser using the PhantomJS Driver

HeadLess Browser using the PhantomJS Driver

Leave a Reply

Your email address will not be published. Required fields are marked *