UI Testing with Puppeteer - Dario Kondratiuk - E-Book

UI Testing with Puppeteer E-Book

Dario Kondratiuk

0,0
27,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 341

Veröffentlichungsjahr: 2021

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



UI Testing with Puppeteer

Implement end-to-end testing and browser automation using JavaScript and Node.js

Dario Kondratiuk

BIRMINGHAM—MUMBAI

UI Testing with Puppeteer

Copyright © 2021 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Associate Group Product Manager: Pavan Ramchandani

Publishing Product Manager: Kaustubh Manglurkar

Senior Editor: Sofi Rogers

Content Development Editor: Aamir Ahmed

Technical Editor: Shubham Sharma

Copy Editor: Safis Editing

Project Coordinator: Manthan Patel

Proofreader: Safis Editing

Indexer: Tejal Daruwale Soni

Production Designer: Shankar Kalbhor

First published: March 2021

Production reference: 1100321

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80020-678-6

www.packt.com

To God, who makes all things possible.

To my wife, Abigail, for all her unconditional support all these years. I am who I am thanks to you.

To my dad, Carlos. You always knew that I was going to write a book.

-Dario Kondratiuk

Contributors

About the author

Dario Kondratiuk has been a web developer since 2001. He won the Microsoft MVP (Most Valuable Professional) award in 2020 for his contributions to the developer community. Dario has been working with Puppeteer since the beta versions, back in 2017. He is the author of Puppeteer-Sharp, a Puppeteer port to .NET, and Playwright-Sharp, a Playwright port to .NET. He writes about web automation on his blog, https://www.hardkoded.com, and he's active on Stack Overflow.

I want to thank my family, Abigail, Carlos, Graciela, Yanel, Eduardo, and Nacho, for all their support during this project. I would also like to thank Mauro, Ezequiel, Facundo, Lucas, Javier, Fede, and Fercho, for helping me be a better professional. Lastly, I would like to thank Pablo, Roge, Fran, Faa, Marcos, Martin, Jere, and Christian for helping me be a better person.

About the reviewers

David Rubio Vidal is a senior software test engineer, AWS solutions architect, and professional Scrum Master with international and multi-disciplinary experience in software engineering. He has worked in the subsea/oil and gas, aerospace, and multimedia industries as well as in the public sector. Regarding software testing, he has proven experience at all levels and disciplines: from UI to API, accessibility, layout, mobile, and more. David is also capable of deploying and managing infrastructure in the cloud, with cutting-edge technologies and methodologies. Finally, as well as working as a software engineer, he has developed his career as a Scrum Master to ensure Agile methodologies are applied properly in the teams he has worked with.

Jim Munro has two decades of professional experience as a test automation engineer. He is passionate about the quality and usability of software and generally enjoys breaking things.

He has spent most of his career writing code in Python and JavaScript and testing with tools such as Puppeteer, Cypress, and Selenium. He lives near Boulder, Colorado with his wife, his daughter, Stella, and their dog, Kipper. He can be reached via email at [email protected] or on Twitter as @jimfmunro.

I would like to thank Manthan Patel, Nitin Nainani, and the team at Packt Publishing. For my parents, Bill and Patricia, who have kindly never asked me to be their tech support.

Table of Contents

Preface

Chapter 1: Getting started with Puppeteer

What is browser automation?

Selenium and Puppeteer

Introducing Headless browsers

Available headless browsers

The Chromium DevTools Protocol

Introducing Puppeteer

The Puppeteer object model

Puppeteer use cases

Task Automation

Web Scraping

Content generation

End-to-end testing

Setting up the environment

Node.js

Visual Studio Code

Our first Puppeteer code

Installing Puppeteer

Hello world in Puppeteer

Asynchronous programming in JavaScript

Promise.all

Promise.race

Fulfilling our own promises

Summary

Chapter 2: Automated Testing and Test runners

Technical requirements

Introduction to Automated Testing

Unit tests

Service tests

End-to-end tests

Test runner features

Available test runners

Creating our first test project

Organizing our code

Introducing the Page Object Model

Summary

Chapter 3: Navigating through a website

Technical requirements

Introducing the tests sites for this chapter

Creating a Puppeteer browser

Using the Puppeteer.launch function

Headless

The user data directory

Executable Path

Default Viewport

Product

Browser Arguments

Mobile options

Options in practice

Navigating through a site

Timeouts

waitUntil

Referrer

Using the response object

Getting the response URL

Getting the response status code

Introduction to continuous integration

Summary

Chapter 4: Interacting with a page

Technical requirements

Introduction to HTML, the DOM, and CSS

HTML

The DOM

CSS Selectors

Finding elements

Finding elements using XPath

Interacting with Elements

Typing on input elements

Clicking on elements

Selecting options in drop-down lists

Keyboard and Mouse emulation

Debugging tests with Visual Studio Code

Summary

Chapter 5: Waiting for elements and network calls

Technical requirements

Waiting for the page to load

Waiting for elements

Await a wait function

Waiting for network calls

Arrange, Act, Await

Fire and forget

Promise.all

Waiting for page events

The close event

The popup event

Target created event

The console event

The dialog event

The headless recorder

Summary

Chapter 6: Executing and Injecting JavaScript

Technical requirements

Executing JavaScript code

Variable scopes in JavaScript

Manipulating handles with JavaScript code

Getting information from the elements

Acting on elements

Enforcing server rules

Finding elements using JavaScript

Waiting for functions

Exposing local functions

Running our checks with Checkly

Summary

Chapter 7: Generating Content with Puppeteer

Technical requirements

Taking screenshots

Using screenshots for regression tests

Generate PDF files

Creating HTML content

Summary

Chapter 8: Environments emulation

Technical requirements

Understanding the browser's market share

The browser's popularity over the years

Operative Systems market share

Screen resolution distribution

Emulating mobile devices

The Viewport

Pixel ratio

The touchscreen

The user agent

Emulating mobile devices with Puppeteer

Emulating network conditions

Emulating localization

Emulating geolocation

Emulating time zones

Emulating languages

Other emulations

Summary

Chapter 9: Scraping tools

Technical requirements

Introduction to web scraping

Does the site allow scrapers?

Creating scrapers

Running scrapers in parallel

How to avoid being detected as a bot

Dealing with authorization

Summary

Chapter 10: Evaluating and Improving the Performance of a Website

Technical requirements

The Issue of Performance

Getting started with Google Lighthouse

As part of Chrome DevTools

Using PageSpeed Insights

Using the command line

Using the node module

The performance category

Using Lighthouse for testing

Tracing Pages

Analyzing code coverage

Summary

Why subscribe?

Other Books You May Enjoy