Book Image

UI Testing with Puppeteer

By : Dario Kondratiuk
Book Image

UI Testing with Puppeteer

By: Dario Kondratiuk

Overview of this book

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.
Table of Contents (12 chapters)

Setting up the environment

What's good about Node.js and Puppeteer is that they are cross-platform. My local environment is macOS Catalina 10.15.6. But you won't see much difference if you use a Windows or a Linux environment.

Time is a tech book's worst enemy. At the time of writing this book, I was using Node.JS 12.18.3 and Puppeteer 7. I'm pretty sure that by the time you read this book, new versions will have come to light. But don't feel discouraged about that; we expect that to happen. That's why I encourage you to go now and take a look at the GitHub repository of this book (https://github.com/PacktPublishing/ui-testing-with-Puppeteer). If you see that something is not working or has changed, please create an issue on that repository. We will try to keep it updated.

We only need two things to run our first Puppeteer code: Node.JS and Puppeteer. Let's begin with Node.JS.

Node.js

For the purposes of this book, the only thing you need...