Thursday, January 4, 2018

Headless Automation Testing using Selenium and PhantomJS.

In the previous post How does Headless Testing helps in Software Testing? we have seen the advantages of Headless testing of a software. In this post we will learn executing a test case using headless browser.

There are different tools available for carrying out the headless testing some are listed below:
  • HtmlUnitDriver
  • PanthonJS
  • Nightmare
  • Headless Chrome
We will be focusing on headless testing using Selenium and PanthomJS. PanthomJS is a webkit which runs headless with an inbuilt JavaScript API. It has fast and native support for various web standards such as DOM handling, CSS selector and JSON.

PhanthomJS uses WebDriver Wire Protocal implementation, which is achieved by running the GhostDriver at the back end of the PanthomJS.

I will be using Eclipse, TestNG, and Selenium WebDriver for demo.

Step 1: Create a TestNG project and add the required Selenium Standalone Server jar file to the project.


Step 2: Download PanthomJS binary executable file from their official website and extract the files in it looks something like below



Step 3: Inside the bin folder we will find the executable file. Keep that executable in the project current directory, you can keep anywhere in the system to make it more structured i am keeping the required jar files in 'libs' folder in my case.


Step 3: Like we access geckodriver for Firefox, chromedriver for Chrome browsers we need to set the system property "panthomjs.binary.path" to access PhantomJS headless browser.

System.setProperty("phantomjs.binary.path", System.getProperty("user.dir")+"\\libs\\phantomjs.exe");

Step 4: We are done with setup. Write a test case and execute it as TestNG test

Step 5: Test execution is completed without launching a browser UI. It printed the title of the in the console as well


This is a gist about headless testing using PhantomJS. Please share your comments and suggestions on this topic. Thanks for reading!!

#seleniumbabu #HappyLearning

2 comments:

  1. Wonderful post!!Thank you for sharing this info with us.
    Keep updating I would like to know more updates on this topic
    Very useful content, I would like to suggest this blog to my friends.

    Best selenium Training Institute in Chennai

    best selenium training in chennai

    ReplyDelete
  2. I have read your blog completely. It is very impressive one for all the viewers. Thanks for sharing this blog.

    selenium training in chennai

    ReplyDelete

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...