# Performance Testing

If you don’t want users leaving the app you have to think of performance. In fact nowadays if you site is not fast enough you get even “honored” with [the badge of shame](https://www.theverge.com/2019/11/11/20959865/google-chrome-slow-sites-badge-system-chrome-dev-summit-2019) from Google. Thus [performance budget](https://addyosmani.com/blog/performance-budgets/) is one of the aspects we address with end-to-end tests and include in CI/CD pipeline to ensure new releases do comply our requirements.&#x20;

With Puppetry we can assert that:&#x20;

* Page loading times comply given restrictions&#x20;
* Total weight of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page satisfies given budget.&#x20;
* Total number of requested of assets satisfies given budget&#x20;

## Milestone timings&#x20;

With `page.assertPerformanceTiming` method we can establish budget for loading times. Namely:

* **Page loading**: the whole process of navigation and page load
* **Redirection**: the time taken by document request redirections
* **Network latency**: the time taken to fetch app cache, lookup domain, establish TCP connection, send request, receive response
* **Page processing**: the time taken for page load once the page is received from the server

![Asserting page loading times](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2OjX-wJy7cnHleqi4%2Fperf1.1.png?alt=media\&token=b72e0280-533c-408e-8bf9-455e8547f433)

In case of assertion failure we get a report like this:

![Page loading budget report](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2OeylKoxBFHyAl4IF%2Fperf1.2.png?alt=media\&token=6a9fe88c-3746-4172-af77-66c53ae2e25d)

## Quantity-based metrics

With `page.assertPerformanceAssetWeight` method we can assert the total weight of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page

![Asserting total weight of requested assets ](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2L1z9apr2OOpIW1X4%2Fperf2.png?alt=media\&token=6867197a-a288-48b3-a860-ccf1a607e309)

In case of assertion failure we get a report like this:

![Assertion failed](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2PJcfJB3lCovdo2OM%2Fperf2.2.png?alt=media\&token=8ded25de-b396-4d64-a606-4067373de325)

By clicking on **Download performance report**

![Download performance report button](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2PNYSjZQ1T-YtkTc0%2Fperf2.3.png?alt=media\&token=6dd4237b-025b-4c59-8f4c-154af786dae9)

we can get the network activity details

![Performance report as a text file](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2PQvFQ7BXnWLSyPDq%2Fperf2.4.png?alt=media\&token=6a7167bd-3053-4ca2-92fb-9076193d9d4c)

With `page.assertPerformanceAssetCount` method we can assert the total number of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page

![Asserting total number of requested assets ](https://3461068122-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-Lu298PA-rOVANhVIEj1%2F-Lu2L5UAR59D_NC6yeuf%2Fperf3.png?alt=media\&token=e135a1fa-1be1-463f-9166-df897add698d)
