0%

Write fail-safe automation tests, device emulation, and browser automation using Puppeteer's Google-powered API

Key Features

  • Get up and running with Puppeteer and discover best practices for automation testing
  • Automate your modern web applications using Jest and Mocha with Puppeteer
  • Generate screenshots using Puppeteer and find out how they can be used for UI regression tests

Book Description

Puppeteer is an open source web automation library created by Google to perform tasks such as end-to-end testing, performance monitoring, and task automation with ease. Using real-world use cases, this book will take you on a pragmatic journey, helping you to learn Puppeteer and implement best practices to take your automation code to the next level!

Starting with an introduction to headless browsers, this book will take you through the foundations of browser automation, showing you how far you can get using Puppeteer to automate Google Chrome and Mozilla Firefox. You'll then learn the basics of end-to-end testing and understand how to create reliable tests. You'll also get to grips with finding elements using CSS selectors and XPath expressions. As you progress through the chapters, the focus shifts to more advanced browser automation topics such as executing JavaScript code inside the browser. You'll learn various use cases of Puppeteer, such as mobile devices or network speed testing, gauging your site's performance, and using Puppeteer as a web scraping tool.

By the end of this UI testing book, you'll have learned how to make the most of Puppeteer's API and be able to apply it in your real-world projects.

What you will learn

  • Understand browser automation fundamentals
  • Explore end-to-end testing with Puppeteer and its best practices
  • Apply CSS Selectors and XPath expressions to web automation
  • Discover how you can leverage the power of web automation as a developer
  • Emulate different use cases of Puppeteer such as network speed tests and geolocation
  • Get to grips with techniques and best practices for web scraping and web content generation

Who this book is for

The book is for QA engineers, testing professionals, and frontend web developers alike who want to perform end-to-end testing using Google's developer tools. Web developers who want to learn how to use Puppeteer for generating content, scraping websites, and evaluating website performance will also find this book useful. Although knowledge of Node.js isn't necessary, basic JavaScript knowledge will assist with understanding the concepts covered.

Table of Contents

  1. UI Testing with Puppeteer
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Disclaimer
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Reviews
  6. Chapter 1: Getting started with Puppeteer
    1. What is browser automation?
    2. Selenium and Puppeteer
    3. Introducing Headless browsers
    4. Available headless browsers
    5. The Chromium DevTools Protocol
    6. Introducing Puppeteer
    7. The Puppeteer object model
    8. Puppeteer use cases
    9. Task Automation
    10. Web Scraping
    11. Content generation
    12. End-to-end testing
    13. Setting up the environment
    14. Node.js
    15. Visual Studio Code
    16. Our first Puppeteer code
    17. Installing Puppeteer
    18. Hello world in Puppeteer
    19. Asynchronous programming in JavaScript
    20. Promise.all
    21. Promise.race
    22. Fulfilling our own promises
    23. Summary
  7. Chapter 2: Automated Testing and Test runners
    1. Technical requirements
    2. Introduction to Automated Testing
    3. Unit tests
    4. Service tests
    5. End-to-end tests
    6. Test runner features
    7. Available test runners
    8. Creating our first test project
    9. Organizing our code
    10. Introducing the Page Object Model
    11. Summary
  8. Chapter 3: Navigating through a website
    1. Technical requirements
    2. Introducing the tests sites for this chapter
    3. Creating a Puppeteer browser
    4. Using the Puppeteer.launch function
    5. Headless
    6. The user data directory
    7. Executable Path
    8. Default Viewport
    9. Product
    10. Browser Arguments
    11. Mobile options
    12. Options in practice
    13. Navigating through a site
    14. Timeouts
    15. waitUntil
    16. Referrer
    17. Using the response object
    18. Getting the response URL
    19. Getting the response status code
    20. Introduction to continuous integration
    21. Summary
  9. Chapter 4: Interacting with a page
    1. Technical requirements
    2. Introduction to HTML, the DOM, and CSS
    3. HTML
    4. The DOM
    5. CSS Selectors
    6. Finding elements
    7. Finding elements using XPath
    8. Interacting with Elements
    9. Typing on input elements
    10. Clicking on elements
    11. Selecting options in drop-down lists
    12. Keyboard and Mouse emulation
    13. Debugging tests with Visual Studio Code
    14. Summary
  10. Chapter 5: Waiting for elements and network calls
    1. Technical requirements
    2. Waiting for the page to load
    3. Waiting for elements
    4. Await a wait function
    5. Waiting for network calls
    6. Arrange, Act, Await
    7. Fire and forget
    8. Promise.all
    9. Waiting for page events
    10. The close event
    11. The popup event
    12. Target created event
    13. The console event
    14. The dialog event
    15. The headless recorder
    16. Summary
  11. Chapter 6: Executing and Injecting JavaScript
    1. Technical requirements
    2. Executing JavaScript code
    3. Variable scopes in JavaScript
    4. Manipulating handles with JavaScript code
    5. Getting information from the elements
    6. Acting on elements
    7. Enforcing server rules
    8. Finding elements using JavaScript
    9. Waiting for functions
    10. Exposing local functions
    11. Running our checks with Checkly
    12. Summary
  12. Chapter 7: Generating Content with Puppeteer
    1. Technical requirements
    2. Taking screenshots
    3. Using screenshots for regression tests
    4. Generate PDF files
    5. Creating HTML content
    6. Summary
  13. Chapter 8: Environments emulation
    1. Technical requirements
    2. Understanding the browser's market share
    3. The browser's popularity over the years
    4. Operative Systems market share
    5. Screen resolution distribution
    6. Emulating mobile devices
    7. The Viewport
    8. Pixel ratio
    9. The touchscreen
    10. The user agent
    11. Emulating mobile devices with Puppeteer
    12. Emulating network conditions
    13. Emulating localization
    14. Emulating geolocation
    15. Emulating time zones
    16. Emulating languages
    17. Other emulations
    18. Summary
  14. Chapter 9: Scraping tools
    1. Technical requirements
    2. Introduction to web scraping
    3. Does the site allow scrapers?
    4. Creating scrapers
    5. Running scrapers in parallel
    6. How to avoid being detected as a bot
    7. Dealing with authorization
    8. Summary
  15. Chapter 10: Evaluating and Improving the Performance of a Website
    1. Technical requirements
    2. The Issue of Performance
    3. Getting started with Google Lighthouse
    4. As part of Chrome DevTools
    5. Using PageSpeed Insights
    6. Using the command line
    7. Using the node module
    8. The performance category
    9. Using Lighthouse for testing
    10. Tracing Pages
    11. Analyzing code coverage
    12. Summary
    13. Why subscribe?
  16. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
54.172.169.199