×

Top 15 PhantomJS Interview Question for 2024

1) What is PhantomJS?

PhantomJS is a lightweight headless scripted browser built on WebKit. It is used for automation web page interaction.

2) Why it is called as headless browser?

PhantomJS called as headless browser because it execution does not happen on browser which means there is no involvement of browser while executing JavaScript code, it takes over terminal.

3) What is WebKit?

WebKit is software component used for rendering web pages in web browsers (Chrome, Safari as well as other).

4) What are the objects in PhantomJS.

These are the following objects in PhantomJs:
    1. cookiesEnabled: It check whether cookie are enable or not. It return true for yes otherwise false. Its default value is true.
Syntax:
  1. phantom.cookiesEnabled
    1. cookies: It is used to get or set cookies from domain which are stored in Cookiejar. Cookie returns an object with all cookies available for the domain.
Syntax:
  1. phantom.cookies
    1. libraryPath: It store the script path which are used by injectJs function.
Syntax:
  1. phantom.libraryPath
    1. version: It is a read-only property which return version of PhantomJS instance which are running. The details are return in an object ('major': 1,'minor': 7, 'patch': 0).
Syntax:
  1. phantom.version
    1. scriptName: It is used to get current script name (this property has depreciated).
Syntax:
  1. phantom.scriptName
    1. args: It contain the script name as its first element (this property has removed).
Syntax:
  1. phantom.args

5) Name some method of PhantomJS.

Following methods are helping us to execute JavaScript without the browser:
    1. addCookie: This method is used for adding cookies in CookieJar. If successfully added it return true otherwise false.
phantom.addCookie({  

    'name' : 'Cookie name',  

    'value' : 'Cookie value',  

    'domain' : 'localhost'  

});
    1. clearCookies: This method used to delete all the cookies from Cookiejar.
  1. phantom.clearCookies();
    1. deleteCookie: It is used for deleting cookie from Cookiejar by using 'name' property
matching chookieName.  

phantom.deleteCookie('Cookie name');
    1. exit: This method exit the program when return specific return value. It there is no specific return value it return '0'.
specific return value it return '0'.  

if(condation){  

    phantom.exit(1);  

}else{  

phantom.exit(0):  

}
    1. injectJs: It injects external file from specified file into phantom. If file does not found in current directory, then libraryPath property of Phantos is used as an additional place to track the path.
var addSuccess= phantom.injectJs(filename);  

consol.log(addSuccess);  

phantom.exit();

6) What is webpage module property? Name some of them.

Webpage module property provides a facility to interact with contents inside a webpage. Some module properties are:
canGoBack

canGoForward

clipRect

Content

Cookies

customHeaders

Even

focusedFrameName

frameContent

frameName
etc.

7) What is webpage module method? Name some of them.

Webpage module keeps the method for Cookies, Frames, Page Navigation, Reload, Rendering and Uploading of Files. Some webpage module methods are:
addCookie()

clearCookies()

deleteCookie()

getPage()

goBack()

goForword()

go()

includes()

injectJs()

childFramesCount()

childFramesName()

currentFrameName()
etc.

8) What do you understand about screen capture?

PhantomJs provide facility capture screenshot of web page. This capture image can be saved in different formate such as .png, .jpeg, .pdf, .gif. It is also able to convert as PDF. Following script show the simple way for screen capture.
var page = require(‘webpage’).create();  

page.open(‘website_url’,function(status){  

page.render(‘imagename.png’);  

phantom.exit();  

});

9) How network monitoring is done in PhantomJS?

Natwork monitoring is done by using events such as onResourceRequested and DOM manipulation. This helps in monitoring the traffic for given page.

10) What is page automation?

Manipulating and loading of web pages and performing operation such as DOM manipulation by clicking buttons, etc.

11) Is PhantomJS support command line interface (CLI) execution?

Yes, PhantomJS support command line interface execution. CLI execution is done by using keyword "phantomjs" with file name. For example: "phantomjs filename.js".

12) What is the role of child process module in PhantomJS?

Child process module helps to interact with sub processes using stdin /stdout/ stderr. Child processes can be used for performing task like invoke programs, printing, or to sending mail.

13) What is REPL?

REPL is stands for Read Eval Print Loop. In PhantomJS, REPL is an interactive mode to test the JavaScript code.

14) How testing are done in PhantomJS?

PhantomJS is not a test framework. PhantomJS use different libraries known as test runner for testing. Some of the framework along with their test runner is:
Framework Test Runner
Capybara Poltergeit, Terminus
Buster.JS built-in
Mocha Chutzpah, mocha-phantoms
Jasmine Chutzpah, grunt-contrib-jasmine
Hiro built-in
WebDriver GhostDriver

15) What is file system module in PhantomJS?

File system module perform operations on files and directories. We can create, write and delete a files and directory. There are two properties in file system module:  
Separator: It is used for file paths (for windows: \, for linux: /).
Working Directory: It is a directory in which PhantomJS executes.

Related Topics

Top 13 SAS Interview Questions for 2024

1. What is SAS and its functions? SAS (Statistical Analysis System) is statistical software designed by SAS Institute in 1960 for data inspection and report writing. SAS runs on Windows, UNIX...

5 minutes read.

Top 30 RPA Interview questions for 2024

Q1. What is RPA (Robotic Process Automation)? The Robotic Process Automation is a trending technology in the market where: Robotic: Robotic means "machines that copy the human actions." Process: Process means "the sequence of steps which...

12 minutes read.

Top 30 VB Script Interview Questions for 2024

1) What is VB Script? VBScript stands for Visual Basic Scripting Language. It is a light version of Microsoft Visual Basic. It is a client side scripting Language. 2) What is the...

5 minutes read.

Top 30 CSS Interview Questions for 2024

1) Define the process where block elements can be centered with css. It can be centered by using margin-left and margin-right properties we can centered the block level elements. 2) Name the...

4 minutes read.

A to Z Interview Questions

ABCDEFGHIJKLMNOPQRSTUVWXYZ Interview Questions and Answers List A AJAX Interview Questions Android Interview Questions Angular 2 Interview Questions AngularJs Interview Questions Apache Presto Interview Questions Apache Tapestry Interview Questions Arduino Interview Questions ASP.NET MVC Interview Questions Aurelia Interview Questions AWS Interview Questions B Blockchain Interview...

3 minutes read.

Top 30 SASS Interview Questions for 2024

1) What is Sass? SASS: Systematically Awesome Style Sheets is an extension of CSS. It is also known as CSS pre-processor which helps to reduce repetition with CSS and saves time. It is...

4 minutes read.

Top 15 SQL Server Interview Question for 2024

1) Describe SQL Server? SQL server is a DataBase Management System developed by Microsoft. It was first introduced in year 2008 since, then many version has been introduced such as :...

2 minutes read.

Top 30 Sencha Touch Interview Questions for 2024

1) What is Sencha Touch? Sencha Touch is an UI (User Interface) JavaScript library. It is written in JavaScript. It is used to build mobile interface quickly and easily. It works...

6 minutes read.

Top 30 D Programming Language Interview Questions for 2024

1) What is D programming language? D programming language is an object oriented programming language. It is created by Walter Bright of Digital Mars. It was released in 2001. 2) Who is the...

4 minutes read.

WebSockets Interview Questions

1) What is Web Sockets? Web Sockets is a two way communication between the clients and the servers. Here, the clients and servers both the parties can communicate and exchange data...

3 minutes read.

Top 14 Materialize CSS Framework Interview Questions for 2024

1) What is Materialize? Materialize is a CSS framework that contains library file. It is created with CSS, JavaScript and HTML. It helps to create attractive, reliable and functional web pages...

7 minutes read.

Top 27 JavaScript Interview Questions for 2024

1) Define Undeclared and Undefined Variables? Undeclared variable are defined as these variable is neither defined nor exist in the program. If program calls this variable then it causes Runtime error. Undefined variable...

5 minutes read.

Top 15 Bootstrap Interview Questions for 2024

1) Explain what is Bootstrap? It is a Framework which is used for building the web application with minimal effort. Bootstrap is also used for developing responsive, mobile-first web sites. 2) What...

10 minutes read.

Top 18 UiPath Interview Questions for 2024

RPA UiPath Interview Questions and Answers for Fresher  1. What is RPA? RPA is an acronym for Robotic Process Automation. Robotic In RPA, Robotic is termed as an entity or machine which tries to...

7 minutes read.

Top 15 Hadoop Interview Questions for 2024

1) What is Hadoop? Hadoop is a framework which is used to store and process Big Data. It is a distributed computing platform and helps in analyzing Big Data. 2) What are the...

2 minutes read.

Top 28 Firebase Interview Questions for 2024

1) What is Firebase? Firebase is a platform which is used for building Web, IOS and Android applications. It offers: Real time database Different APIs Multiple authentication types and Hosting platform 2) What are the features of...

3 minutes read.

Top 30 Zend Framework Interview Questions for 2024

1) What is Zend Framework? Zend is an open source, object-oriented web application framework. It is implemented in PHP 5. It was developed in 3 March 2006. 2) What is the use...

6 minutes read.

Symfony PHP Framework Interview Questions

1) What is Symfony? Symfony is an open source, web application framework. It is written in PHP and used to design PHP applications. It was first released on18 October, 2005. 2) What...

5 minutes read.

Top 10 GWT Interview Questions for 2024

1) What is Google Web Toolkit (GWT)? GWT (Google Web Toolkit) is a development toolkit. It is used to develop Ajax web applications using Java. GWT compiler translates Java sour ce...

2 minutes read.

Top 43 React Native Interview Questions for 2024

1. What is React Native? React native is an open-source JavaScript framework designed by Facebook for native mobile applications development. It is based on a JavaScript library-React. React Native saves your development...

11 minutes read.