Skip to content

Commit

Permalink
updating content and removing Puppeteer, continued
Browse files Browse the repository at this point in the history
  • Loading branch information
serverless-mom committed Sep 19, 2024
1 parent c140029 commit 96b842c
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 193 deletions.
2 changes: 1 addition & 1 deletion site/content/guides/api-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ As we increase our monitoring coverage across our APIs, we can also increase the
<div class="cards-list">
{{< doc-card class="three-column-card" title="Checkly CLI" description="Understand monitoring as code (MaC) via our Checkly CLI." link="/guides/monitoring-as-code-cli/" >}}

{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with puppeteer and playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}
{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}

{{< doc-card class="three-column-card" title="OpenAPI/Swagger Monitoring" description="OpenAPI and Swagger help users design and document APIs in a way that is readable from both humans and machines." link="/guides/openapi-swagger/" >}}
</div>
4 changes: 2 additions & 2 deletions site/content/guides/end-to-end-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: What is End to End Monitoring? Overview with Examples
displayTitle: End to end monitoring
description: >-
Learn end-to-end monitoring with puppeteer and playwright to test key website flows. Follow our guide that gets you up and running in 10 minutes.
Learn end-to-end monitoring with playwright to test key website flows. Follow our guide that gets you up and running in 10 minutes.
author: Giovanni Rago
avatar: 'images/avatars/giovanni-rago.png'
---
Expand Down Expand Up @@ -37,7 +37,7 @@ The industry has learned to struggle with the challenges this approach presents:

**All of the above lead to higher costs and slower delivery.**

The appearance of mature **headless browser automation tools, such as {{< newtabref href="https://pptr.dev" title="Puppeteer" >}} and {{< newtabref href="https://playwright.dev" title="Playwright" >}}, offers a response** to many of the above issues by allowing testing in the browser without its GUI, which yields higher speed and stability coupled with lower resource consumption.
The appearance of mature **headless browser automation tools, such as {{< newtabref href="https://playwright.dev" title="Playwright" >}}, offer a response** to many of the above issues by allowing testing in the browser without its GUI, which yields higher speed and stability coupled with lower resource consumption.

## E2E monitoring examples

Expand Down
2 changes: 1 addition & 1 deletion site/content/guides/monitoring-as-code-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ Expanding our initial setup from here is easy, please follow these links if you
<div class="cards-list">
{{< doc-card class="three-column-card" title="Monitoring as code" description="Why should the way we manage monitoring be any different?" link="/guides/monitoring-as-code/" >}}

{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with puppeteer and playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}
{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}

{{< doc-card class="three-column-card" title="Setup scripts for API monitoring" description="Setup scripts are a fundamental tool to tailor API checks to your own target endpoints." link="/guides/setup-scripts/" >}}
</div>
2 changes: 1 addition & 1 deletion site/content/guides/monitoring-as-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ As our setup expands, we might want to deploy additional tools to make our lives
<div class="cards-list">
{{< doc-card class="three-column-card" title="Checkly CLI" description="Understand monitoring as code (MaC) via our Checkly CLI." link="/guides/monitoring-as-code-cli/" >}}

{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with puppeteer and playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}
{{< doc-card class="three-column-card" title="End to end monitoring" description="Learn end-to-end monitoring with playwright to test key website flows." link="/guides/end-to-end-monitoring/" >}}

{{< doc-card class="three-column-card" title="Setup scripts for API monitoring" description="Setup scripts are a fundamental tool to tailor API checks to your own target endpoints." link="/guides/setup-scripts/" >}}
</div>
28 changes: 4 additions & 24 deletions site/content/learn/playwright/basics/multitab-flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ menu:
parent: "Basics"
---

Both Puppeteer and Playwright enable us to control multiple browser tabs, albeit in different ways.
Playwright enables us to control multiple browser tabs, albeit in different ways.

## Opening tabs directly

If we are looking to open brand new tabs with which to interact, the setup is rather straightforward for both Puppeteer and Playwright.
If we are looking to open brand new tabs with which to interact, the setup is rather straightforward.

{{< tabs "1" >}}
{{< tab "Playwright" >}}
Expand All @@ -27,12 +27,7 @@ If we are looking to open brand new tabs with which to interact, the setup is ra
```
{{< run-in-checkly "/samples/playwright/multitab-open.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/multitab-open.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/multitab-open.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

## Handling links that open a new tab
Expand All @@ -41,7 +36,6 @@ Controlling tabs that are opened after a click on an element on the page can be

By allowing us to wait for the creation of a child tab with `page.waitForEvent`, Playwright enables us to "catch" it following a click on an element with `target="_blank"`, and then seamlessly interact with any of the currently open tabs.

With Puppeteer we need to follow a different procedure, using `page.waitForTarget` to grab the new tab once it has been opened.

{{< tabs "2" >}}
{{< tab "Playwright" >}}
Expand All @@ -50,24 +44,10 @@ With Puppeteer we need to follow a different procedure, using `page.waitForTarge
```
{{< run-in-checkly "/samples/playwright/multitab-flows.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/multitab-flows.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/multitab-flows.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

Note that, if running Puppeteer in headful mode, you will have to manually bring focus to the new tab, either by bringing it to the front or closing the old one:

{{< tabs "3" >}}
{{< tab "Puppeteer" >}}
```js {hl_lines=["18-21"]}
{{< readfile filename="samples/puppeteer/multitab-headful.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/multitab-headful.js" "puppeteer" >}}
{{< /tab >}}
{{< /tabs >}}

## Further reading

Expand Down
3 changes: 1 addition & 2 deletions site/content/learn/playwright/basics/request-interception.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Request interception enables us to observe which requests and responses are bein

We might want to intervene and filter the outgoing requests. For example, when [scraping web pages](/learn/headless/basics-scraping/), we might want to block unnecessary elements from loading in order to speed up the procedure and lower bandwidth usage.

In the following snippet we are going to abort all requests for images on our test website. We will identify them based off of their [`resourceType`](https://pptr.dev/#?product=Puppeteer&version=v10.2.0&show=api-httprequestresourcetype), while letting all other requests through without modification.

{{< tabs "2" >}}
{{< tab "Playwright" >}}
Expand All @@ -58,7 +57,7 @@ In the following snippet we are going to abort all requests for images on our te

Isolating one or more software components from their dependencies makes them easier to test. We can do so by substituting interactions with such dependencies with simulated, simplified ones. This is also known as _stubbing_.

Both Playwright and Puppeteer make it easy for us, as for every request we can intercept we also can stub a response.
Playwright makes it easy for us, as for every request we can intercept we also can stub a response.

Every time we load it, our test website is sending a request to its backend to fetch a list of best selling books. For our example, we are going to intercept this response and modify it to return a single book we define on the fly.

Expand Down
17 changes: 3 additions & 14 deletions site/content/learn/playwright/basics/taking-screenshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@ Headless browsers are fully capable of taking screenshots, which is very useful

## Generating and saving screenshots

The `page.screenshot` command is consistent across Playwright and Puppeteer, and allows us to save one or more screenshots of the current page to a specified path. Without any additional options, the size of the screenshot depends on the viewport size:
The `page.screenshot` command allows us to save one or more screenshots of the current page to a specified path. Without any additional options, the size of the screenshot depends on the viewport size:

{{< tabs "1" >}}
{{< tab "Playwright" >}}
```js
{{< readfile filename="samples/playwright/basic-screenshot.js" >}}
```
{{< run-in-checkly "/samples/playwright/basic-screenshot.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-screenshot.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-screenshot.js" "puppeteer" >}}
{{< /tab >}}
{{< /tab >}}\s
{{< /tabs >}}

## Full page screenshots
Expand All @@ -56,12 +50,7 @@ Having our screenshot limited to a smaller portion of the viewport is also possi
```
{{< run-in-checkly "/samples/playwright/basic-screenshot-clipped.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-screenshot-clipped.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-screenshot-clipped.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

The above examples can be run as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ menu:
parent: "Best practices"
---

While automation tools are fundamental to modern software development, they also have the innate potential to be used for malicious purposes. This applies to Playwright and Puppeteer, too.
While automation tools are fundamental to modern software development, they also have the innate potential to be used for malicious purposes.

<!-- more -->

Expand Down Expand Up @@ -56,14 +56,7 @@ const page = await context.newPage('https://example.com')

```
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari 537.36 Secret/<MY_SECRET>')

```
{{< /tab >}}
{{< /tabs >}}

## Automation-resistant UIs
Expand Down
65 changes: 12 additions & 53 deletions site/content/learn/playwright/best-practices/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ menu:

The need for fast and responsive applications has never been greater because of the move from [desktop to mobile](https://gs.statcounter.com/platform-market-share/desktop-mobile-tablet/worldwide/). Still, web applications have been increasing in [complexity and size](https://httparchive.org/reports/page-weight). It is clear why the topic of webpage performance is more popular today than it ever was.

This article gives a practical introduction to the whys and hows of web performance without getting lost in the depth of this massive topic. It also explains how to measure performance and gather metrics such as the Web Vitals with headless tools such as Puppeteer and Playwright.
This article gives a practical introduction to the whys and hows of web performance without getting lost in the depth of this massive topic.

<!-- more -->

Expand Down Expand Up @@ -58,7 +58,7 @@ Not all of Google's Web Vitals are suitable for synthetic monitoring and perform
{{</ warning >}}
## Web Performance evaluation with headless tools

As much as we should be striving to build performant applications, we should commit to monitoring and testing performance to enable continuous feedback and rapid intervention in case of degradation. Playwright and Puppeteer provide a great toolkit to power synthetic monitoring and performance testing.
As much as we should be striving to build performant applications, we should commit to monitoring and testing performance to enable continuous feedback and rapid intervention in case of degradation. Playwright provides a great toolkit to power synthetic monitoring and performance testing.

1. Access to the Web Performance APIs.
2. Whenever testing against Chromium, access to the Chrome DevTools Protocol for traffic inspection, network emulation and more.
Expand All @@ -83,12 +83,6 @@ The Navigation Timing and the Resource Timing performance APIs are W3C specifica
```
{{< run-in-checkly "/samples/playwright/basic-performance-navigation.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-navigation.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-navigation.js" "puppeteer" >}}
{{< /tab >}}
{{< /tabs >}}

<details class="console-output">
Expand Down Expand Up @@ -139,12 +133,7 @@ The Navigation Timing and the Resource Timing performance APIs are W3C specifica
```
{{< run-in-checkly "/samples/playwright/basic-performance-resource.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-resource.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-resource.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

<details class="console-output">
Expand Down Expand Up @@ -187,12 +176,7 @@ The Navigation Timing and the Resource Timing performance APIs are W3C specifica
```
{{< run-in-checkly "/samples/playwright/basic-performance-paint-timing.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-paint-timing.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-paint-timing.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

<details class="console-output">
Expand Down Expand Up @@ -220,12 +204,7 @@ To evaluate the LCP initialize a `PerformanceObserver`, observe `largest-content
```
{{< run-in-checkly "/samples/playwright/basic-performance-largest-contentful-paint.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-largest-contentful-paint.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-largest-contentful-paint.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}
#### Layout Instability API (`layout-shift`)

Expand All @@ -242,12 +221,7 @@ Layout shifts are no single event but event streams. To calculate CLS initialize
```
{{< run-in-checkly "/samples/playwright/basic-performance-layout-shift.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-layout-shift.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-layout-shift.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

#### Long Task API (`longtask`)
Expand All @@ -265,17 +239,12 @@ Long Tasks are no single event but event streams. To calculate TBT initialize a
```
{{< run-in-checkly "/samples/playwright/basic-performance-long-task.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-long-task.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-long-task.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

### Chrome DevTools for performance

If the browser performance APIs are not enough, the Chrome DevTools Protocol offers many great performance tools for us to leverage with Playwright and Puppeteer.
If the browser performance APIs are not enough, the Chrome DevTools Protocol offers many great performance tools for us to leverage with Playwright.

One important example is network throttling, through which we can simulate the experience of users accessing our page with different network conditions.

Expand All @@ -286,31 +255,21 @@ One important example is network throttling, through which we can simulate the e
```
{{< run-in-checkly "/samples/playwright/basic-performance-emulation.js" "playwright" >}}
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-emulation.js" >}}
```
{{< run-in-checkly "/samples/puppeteer/basic-performance-emulation.js" "puppeteer" >}}
{{< /tab >}}

{{< /tabs >}}

The DevTools Protocol is quite extensive. We recommend exploring the [documentation](https://chromedevtools.github.io/devtools-protocol/) and getting a comprehensive overview of its capabilities.

### Additional performance libraries

Lighthouse can easily be used programmatically with Playwright and Puppeteer to gather values and scores for different metrics, like [Time To Interactive (TTI)](https://web.dev/interactive/):
Lighthouse can easily be used programmatically with Playwright to gather values and scores for different metrics, like [Time To Interactive (TTI)](https://web.dev/interactive/):

{{< tabs "8" >}}
{{< tab "Playwright" >}}
```js
{{< readfile filename="samples/playwright/basic-performance-lighthouse.js" >}}
```
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/basic-performance-lighthouse.js" >}}
```
{{< /tab >}}
{{< /tabs >}}

All above examples can be run as follows:
Expand All @@ -320,7 +279,7 @@ $ node measure-performance.js

## Further reading
1. The comprehensive [MDN Web Performance documentation](https://developer.mozilla.org/en-US/docs/Web/Performance)
2. [web.dev's performance section](https://web.dev/learn/#performance)
3. [Web Performance Recipes With Puppeteer](https://addyosmani.com/blog/puppeteer-recipes/) by Addy Osmani
2. [Automatically finding accessibility issues with Playwright](https://www.checklyhq.com/blog/integrating-accessibility-checks-in-playwright-tes/)
3. [web.dev's performance section](https://web.dev/learn/#performance)
4. [Getting started with Chrome DevTools Protocol](https://github.com/aslushnikov/getting-started-with-cdp) by Andrey Lushnikov
5. [Get Started with Google Lighthouse](https://developers.google.com/web/tools/lighthouse#get-started)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ menu:
parent: "Best practices"
---

Playwright and Puppeteer can be particularly useful when scraping data accessible only behind a login wall. This article shows a practical example of such a case.
Playwright can be particularly useful when scraping data accessible only behind a login wall. This article shows a practical example of such a case.

<!-- more -->

Expand All @@ -29,11 +29,7 @@ A combination of UI automation and scraping will allow us to first log in to the
{{< readfile filename="samples/playwright/scraping-example-purchases.js" >}}
```
{{< /tab >}}
{{< tab "Puppeteer" >}}
```js
{{< readfile filename="samples/puppeteer/scraping-example-purchases.js" >}}
```
{{< /tab >}}

{{< /tabs >}}

> ⚠️ This example is only intended for learning purposes. Always make sure the website you are planning to scrape allows such behaviour.
Expand Down Expand Up @@ -63,8 +59,8 @@ node scraping-example-purchases.js
> ⚠️ Websites might [restrict headless browser traffic](/learn/headless/challenging-flows/) in order to protect their users from fraud. 2FA will also interfere with the script if enabled.
## Takeaways
1. We can scrape information available behind a login wall with Playwright and Puppeteer.
1. We can scrape information available behind a login wall with Playwright.
2. Some websites might not allow scraping. Always make sure you check their terms of service beforehand.

## Further reading
1. [Basic scraping](/learn/headless/basics-scraping/) with Playwright and Puppeteer
1. [Basic scraping](/learn/headless/basics-scraping/) with Playwright
Loading

0 comments on commit 96b842c

Please sign in to comment.