Getting Started with PhantomJS

Book description

Harness the strength and capabilities of PhantomJS to interact with the web and perform website testing with a headless browser based on WebKit

  • Writing scripts that can interact directly with web services and pages
  • Interacting with social media websites using PhantomJS scripts
  • Creating web-based test scripts and running them in a headless browser

In Detail

PhantomJS is a headless WebKit browser with JavaScript API that allows you to create new ways to automate web testing. PhantomJS is currently being used by a large number of users to help them integrate headless web testing into their development processes. It also gives you developers a new framework to create web-based applications, from simple web manipulation to performance measurement and monitoring.

A step step-by by-step guide that will help you develop new tools for solving web and testing problems in an effective and quick way. The book will teach you how to use and maximize PhantomJS to develop new tools for web scrapping, web performance measurement and monitoring, and headless web testing. This book will help you understand PhantomJS’ scripting API capabilities and strengths.

This book starts by looking at PhantomJS’ JavaScript API, features, and basic execution of scripts. Throughout the book, you will learn details to help you write scripts to manipulate web documents and fully create a web scrapping tool.

Through its practical approach, this book strives to teach you by example, where each chapter focuses on the common and practical usage of PhantomJS, and how to extract meaningful information from the web and other services.

By the end of the book, you will have acquired the skills to enable you to use PhantomJS for web testing, as well as learning the basics of Jasmine, and how it can be used with PhantomJS.

Table of contents

  1. Getting Started with PhantomJS
    1. Table of Contents
    2. Getting Started with PhantomJS
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers and more
      2. Why Subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Getting Started
      1. Downloading PhantomJS
      2. Building PhantomJS from source
      3. Working with PhantomJS
      4. PhantomJS JavaScript API
        1. The Module API
        2. The WebPage API
        3. The System API
        4. The FileSystem API
        5. The WebServer API
      5. The phantom object
      6. The command-line arguments
        1. The script argument
        2. The debug option
        3. The cookie-file option
      7. Writing PhantomJS scripts
      8. Summary
    9. 2. Manipulating Page Content
      1. Opening a web page
      2. Playing with DOM elements
        1. Selecting elements
      3. Simulating mouse clicks
        1. PhantomJS event triggering
        2. DOM event triggering
      4. Working with form fields
      5. Summary
    10. 3. Handling Events and Callbacks
      1. Listening to page events
        1. Page load events
        2. When a resource is requested
        3. Receiving a page resource
          1. Two stages of the resource received event
        4. Knowing when the URL changes
      2. Capturing alert messages
      3. Answering prompt messages
      4. Responding to confirm pop ups - OK or Cancel
      5. Performing user events
        1. Keyboard events
        2. Mouse events
      6. Summary
    11. 4. Capturing Errors
      1. Handling PhantomJS errors
      2. Capturing page script errors
      3. Anticipating the page loading error
      4. Exiting with error codes
      5. Summary
    12. 5. Grabbing Pages
      1. Undocumented supported image format
      2. Screenshot dimensions
      3. Saving web pages as PDFs
      4. Summary
    13. 6. Accessing Location-based Services
      1. Checking a location based on IP address
      2. Getting driving directions
      3. Looking up for pizza delivery establishments
      4. Summary
    14. 7. Working with Files
      1. PhantomJS FileSystem API
      2. Reading files
        1. Checking for file existence
        2. Opening the file
        3. Closing the opened files
      3. Writing files
      4. Character encoding
      5. Summary
    15. 8. Cookies
      1. Reading cookies
      2. Baking some cookies
      3. Deleting cookies
      4. Keeping cookies
      5. Summary
    16. 9. External JavaScript
      1. Modules
      2. Using the object-oriented modules
      3. Using third-party JavaScript libraries
      4. Summary
    17. 10. Testing with PhantomJS
      1. What is unit testing?
      2. Unit testing with Jasmine
        1. Downloading Jasmine
        2. Test specs with Jasmine
        3. The PhantomJS Jasmine runner
      3. Summary
    18. 11. Maximizing PhantomJS
      1. CasperJS
      2. GhostDriver
      3. Screenshots, web metrics, and more
      4. Summary
    19. Index

Product information

  • Title: Getting Started with PhantomJS
  • Author(s): Aries Beltran
  • Release date: November 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781782164227