PhantomJS Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

PhantomJS Interview Questions & Answers

Do you have bachelor degree in computer engineering? Are you blessed with immense knowledge on programming languages? Are you interested to work as Java developer? Then check on the wisdom jobs online and explore yourself. PhathomJS is a scripted, headless browser used for automating web page interaction. It provides a JAVA script API enabling automated navigation, screen shots, user behaviour, assertions making it common tool used to run browse based unit tests in a headless system like continuous integration environment. Various companies are looking for skilled and dynamic candidates with good command over programming languages to work as JAVA developer, software engineer, senior developer, UI developer, etc. So, try your luck by seeing the given listed PhathomJS job interview questions and answers.

PhantomJS Interview Questions

PhantomJS Interview Questions
    1. Question 1. What Is Phantomjs?

      Answer :

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

    2. Question 2. Why It Is Called As Headless Browser?

      Answer :

      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. Question 3. What Is Webkit?

      Answer :

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

    4. Question 4. What Are The Objects In Phantomjs?

      Answer :

      These are the following objects in PhantomJs:

      cookiesEnabled: It check whether cookie are enable or not. It return true for yes otherwise false. Its default value is true.

      Syntax:

      phantom.cookiesEnabled  

      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:

      phantom.cookies  

      libraryPath: It store the script path which are used by injectJs function.

      Syntax:

      phantom.libraryPath  

      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:

      phantom.version  

      scriptName: It is used to get current script name (this property has depreciated).

      Syntax:

      phantom.scriptName  

      args: It contain the script name as its first element (this property has removed).

      Syntax:

      phantom.args  

    5. Question 5. Name Some Method Of Phantomjs?

      Answer :

      Following methods are helping us to execute JavaScript without the browser:

      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'  

      });  

      clearCookies: This method used to delete all the cookies from Cookiejar.

      phantom.clearCookies();  

      deleteCookie: It is used for deleting cookie from Cookiejar by using 'name' property

      matching chookieName.  

      phantom.deleteCookie('Cookie name');  

      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):  

      }  

      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. Question 6. What Is Webpage Module Property? Name Some Of Them?

      Answer :

      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. Question 7. What Is Webpage Module Method? Name Some Of Them?

      Answer :

      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. Question 8. What Do You Understand About Screen Capture?

      Answer :

      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. Question 9. How Network Monitoring Is Done In Phantomjs?

      Answer :

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

    10. Question 10. What Is Page Automation?

      Answer :

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

    11. Question 11. Is Phantomjs Support Command Line Interface (cli) Execution?

      Answer :

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

    12. Question 12. What Is The Role Of Child Process Module In Phantomjs?

      Answer :

      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. Question 13. What Is Repl?

      Answer :

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

    14. Question 14. How Testing Are Done In Phantomjs?

      Answer :

      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. Question 15.  what Is File System Module In Phantomjs?

      Answer :

      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.

Popular Interview Questions

All Interview Questions

All Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Tutorial