You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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!
49
49
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
-
asyncfunctionwithPage(test) {
56
-
constbrowser=awaitpuppeteer.launch();
57
-
constpage=awaitbrowser.newPage();
58
-
try {
59
-
awaittest(page);
60
-
} finally {
61
-
awaitpage.close();
62
-
awaitbrowser.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.
The ability to extend and customize fixtures in Playwright not only reduces boilerplate but also enhances test isolation and reusability across your test suite.
94
71
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.
100
72
101
73
## Create a Custom Test Fixture in Playwright Test
102
74
@@ -110,8 +82,8 @@ First, create a new test file or use an existing one. Here, we're testing a web
110
82
111
83
To create a custom fixture, extend the `test` object provided by Playwright:
112
84
113
-
```js
114
-
// fixture.js
85
+
```js {title="fixture.js"}
86
+
115
87
import { testasbaseTest } from'@playwright/test';
116
88
117
89
consttest=baseTest.extend({
@@ -158,8 +130,8 @@ Debugging is crucial to ensure your fixture works as expected. Playwright's insp
158
130
159
131
To share your custom fixture across different test files, encapsulate it in a separate module:
exportconsttest=baseTest.extend({ /* Your fixture definition */ });
@@ -168,8 +140,7 @@ export { expect };
168
140
169
141
Then, in your test files, import this extended `test` and use the custom fixtures:
170
142
171
-
```js
172
-
// tests/your-test.spec.js
143
+
```js {title="tests/your-test.spec.js"}
173
144
import { test, expect } from'./setup';
174
145
```
175
146
@@ -243,6 +214,6 @@ Custom test fixtures in Playwright streamline test setup and teardown, fostering
243
214
244
215
### Playwright Fixtures Explained on YouTube
245
216
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.
0 commit comments