Skip to content

Commit 76eb358

Browse files
finished the revisions of test-fixtures
1 parent 8991c64 commit 76eb358

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Automating Check Steps for Developers
3+
displayTitle: Involve Every Developer in Monitoring with Automated Setup
4+
description: >-
5+
When we enable developers to create page or API monitors, we want to automate as much of the code writing process as possible, so that developers can test the functionality they care about without getting bogged down in setup steps.
6+
author: Nočnica Mellifera
7+
avatar: 'images/avatars/nica-mellifera.png'
8+
tags:
9+
- FAQ
10+
---
11+
## To involve developers in monitoring, you need to make it easy
12+
13+
[Insert some more 'why' here]
14+
15+
This guide will tie together material from our Playwright Learn articles, our blog, and our tutorial videos, to help you create an environment for developers that makes it easy for them to add new page checks with minimal repetitive code. We'll cover:
16+
17+
{{ .TableOfContents }}
18+
19+
* The Checkly CLI and Monitoring as Code for developers
20+
* Creating standardized configuration for checks and groups of checks
21+
* Automating repeated tasks like account logins so the code can be re-used in multiple checks
22+
* Adding standardized code that runs with every check
23+
* Standard code for ignoring elements
24+
* Golden Files - creating and updating comparison files
25+
26+
## The Checkly CLI and Monitoring as Code for developers
27+
28+
29+
## Grouping Checks and Standardizing Configuration
30+
31+
It's a great feature of Checkly that any check can have totally custom settings for every aspect of its running: it can run at a custom cadence, from its own geography, with its own logic for retries. This means that if, for example, you're creating a new test specifically to check localization settings, you can set just that check to run from dozens of geographies, even if most checks only need three or four.
32+
33+
Of course, we don't want to give our fresh developer over a dozen settings that she needs to set just to create her first check. New Checks created

site/content/learn/playwright/test-fixtures.md

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ When writing multiple tests for a single site or service, you're likely to end u
2727
## Why we need custom fixtures
2828
In our web shop, we've got a login process that we want to simulate and test before doing further account actions:
2929

30-
![A web shop login dialog](/samples/images/totp-1.jpeg)
30+
![A web shop login dialog](/samples/images/webshop-login.png)
3131

3232
To open this dialog and log in, we might use some lines like the following:
3333

@@ -47,29 +47,6 @@ test('test', async ({ page }) => {
4747

4848
This is a fine practice for a single test, but if we have dozens that all require login as a first step, we'll find ourself copying and pasting this code several times. This means a lot of copied code, such that if we ever tweak the login process, we'll have to update this copied code in dozens of places, not good!
4949

50-
### Custom Test Fixture Implementation
51-
52-
To use fixtures in Puppeteer, developers typically create helper functions or classes that encapsulate setup and teardown logic. This method requires more upfront work and a good understanding of asynchronous JavaScript patterns.
53-
54-
```js
55-
async function withPage(test) {
56-
const browser = await puppeteer.launch();
57-
const page = await browser.newPage();
58-
try {
59-
await test(page);
60-
} finally {
61-
await page.close();
62-
await browser.close();
63-
}
64-
}
65-
66-
// Usage
67-
withPage(async (page) => {
68-
// Test actions using the page
69-
});
70-
```
71-
72-
This pattern mimics fixture behavior but lacks the built-in, framework-level support found in Playwright, potentially leading to more complex and less maintainable test suites.
7350

7451
## Playwright and Fixtures
7552

@@ -92,11 +69,6 @@ test('My authenticated test', async ({ page }) => {
9269

9370
The ability to extend and customize fixtures in Playwright not only reduces boilerplate but also enhances test isolation and reusability across your test suite.
9471

95-
## Choosing between Puppeteer and Playwright
96-
97-
While both Puppeteer and Playwright offer powerful capabilities for browser automation, their approach to fixtures represents a significant difference in philosophy. Puppeteer offers flexibility and direct control, requiring developers to implement their own fixture-like functionality. Playwright, in contrast, integrates fixtures deeply into its testing framework, promoting code reuse, maintainability, and ease of use.
98-
99-
Choosing between Puppeteer and Playwright will depend on your project's specific needs, the complexity of your tests, and your team's familiarity with JavaScript testing patterns. If fixtures and test structure are a priority, Playwright Test might be the more suitable choice. However, for projects that require fine-grained browser control and are less concerned with test setup and teardown complexity, Puppeteer remains a strong option.
10072

10173
## Create a Custom Test Fixture in Playwright Test
10274

@@ -110,8 +82,8 @@ First, create a new test file or use an existing one. Here, we're testing a web
11082

11183
To create a custom fixture, extend the `test` object provided by Playwright:
11284

113-
```js
114-
// fixture.js
85+
```js {title="fixture.js"}
86+
11587
import { test as baseTest } from '@playwright/test';
11688

11789
const test = baseTest.extend({
@@ -158,8 +130,8 @@ Debugging is crucial to ensure your fixture works as expected. Playwright's insp
158130

159131
To share your custom fixture across different test files, encapsulate it in a separate module:
160132

161-
```js
162-
// setup.js
133+
```js {title="setup.js"}
134+
163135
import { test as baseTest, expect } from '@playwright/test';
164136

165137
export const test = baseTest.extend({ /* Your fixture definition */ });
@@ -168,8 +140,7 @@ export { expect };
168140

169141
Then, in your test files, import this extended `test` and use the custom fixtures:
170142

171-
```js
172-
// tests/your-test.spec.js
143+
```js {title="tests/your-test.spec.js"}
173144
import { test, expect } from './setup';
174145
```
175146

@@ -243,6 +214,6 @@ Custom test fixtures in Playwright streamline test setup and teardown, fostering
243214

244215
### Playwright Fixtures Explained on YouTube
245216

246-
To discover more practical fixture examples, check out our YouTube playlist, which covers fixtures in even more depth.
217+
To discover more practical fixture examples, check out our [YouTube playlist](https://www.youtube.com/watch?v=hegZS46J0rA&list=PLMZDRUOi3a8N067UNvkxXEThKlTII_OJ-), which covers fixtures in even more depth.
247218

248219
{{< youtube-gallery id="PLMZDRUOi3a8N067UNvkxXEThKlTII_OJ-" >}}

0 commit comments

Comments
 (0)