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)

Using the response object

The response is an important concept on the web. There is a corresponding response for every request the browser sends to the server.

It makes sense that the goto returns a response. It makes a request, and the result is the corresponding response.

There are many things we can do with the response. We won't cover all the functionality in this chapter. But these are the most relevant functions we can use as a response to a goto action.

Getting the response URL

Why would I want to know the URL if I know the URL I want to go to?

The server could redirect you to another page. For instance, if you open the browser in incognito/private mode and navigate to https://mail.google.com/, you will see that the server redirects you to https://accounts.google.com/signin.

I'm not saying that you should always check the response URL just in case, but you have to know that the site you are testing might behave like that. One common scenario is the...