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)

Emulating mobile devices

The first type of emulation I want to cover is mobile emulation. In this section, we will cover the three elements that Puppeteer can emulate: The viewport, the touchscreen, and the user agent. We have to keep in mind that it is a browser trying to emulate a mobile device. Puppeteer and Chromium won't be able to emulate any hardware limitations or any other specific features that certain mobile phones offer. There is no real device behind the curtains; it's just a browser trying to show you how a website would look on that device's screen.

As I mentioned previously, 55% of the internet traffic comes from mobile devices. Most of the diversity we saw in the previous section is in the mobile world.

Let's take a look at some of the browser distribution in the mobile world:

Browser market share in mobile devices according to StatCounter

The mobile market is mostly divided between Chrome and Safari. One thing you...