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)

Chapter 5: Waiting for elements and network calls

I won't say I'm old, but I started browsing the internet in the late 90s. So yes, I'm old. Back then, you would sometimes have to wait over a minute to get a page loaded. You might be thinking, "So if you had 10 tabs open, that would be impossible to use." Well, browsers didn't have tabs! Downloading one single MP3 file could take you an hour.

In the early 2000s, the web got into the corporate world, and we started developing business apps using websites. But that was a decision from an IT department. Old terminal apps were hard to update and introduce new features, and desktop apps were hard to distribute. Web apps were the IT department's solution, leaving users with slow and non-user-friendly web apps.

Developers were trying to do their best with the tools they had back then. Pages were mostly generated on the server side using tools such as ASP 3.0 or PHP. AJAX was used for small tasks,...