Skip to content

Commit ef620b8

Browse files
feat: add playwright check examples [kit-2234] (#1156)
* feat: add playwright check examples [kit-2234] * feat: add missing files * fix: set correct dirpath to copy pw settings [kit-2234] * feat: change PW version on examples * Review Maxi's PR around examples without push permissions (#1160) * improve ts advanded example * remove techniches example that fails consistently * update boilerplate TS template example * tweak advanced JS example * tweak readme and homepage spec * * JS simple example * Clarify deploy names to know which suites examples are used more JS vs TS * Align readmes * Include dependencies install step and clarify playwright test usage --------- Co-authored-by: Maxi Gimenez <[email protected]> * chore: remove results * chore: remove package-lock.json * chore: change package.json * fix: do not copy pw config --------- Co-authored-by: María de Antón <[email protected]>
1 parent dafaaa7 commit ef620b8

File tree

27 files changed

+344
-80
lines changed

27 files changed

+344
-80
lines changed

examples/advanced-project-js/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ npm create checkly@latest -- --template advanced-project
1515

1616
This project has examples of all Checkly check types and showcases some advanced features. It also adds a GitHub Actions workflow.
1717

18+
- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly.
19+
1820
- Running `npx checkly test` will look for `.check.js` files and `.spec.js` in `__checks__` directories and execute them in a dry run.
1921

2022
- Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the
@@ -30,6 +32,7 @@ Run the core CLI commands with `npx checkly <command>`
3032
| Command | Action |
3133
|:---------------------|:-------------------------------------------------|
3234
| `npx checkly test` | Dry run all the checks in your project |
35+
| `npx checkly pw-test`| Run playwright tests in your project |
3336
| `npx checkly deploy` | Deploy your checks to the Checkly cloud |
3437
| `npx checkly login` | Log in to your Checkly account |
3538
| `npx checkly --help` | Show help for each command. |
@@ -38,11 +41,14 @@ Run the core CLI commands with `npx checkly <command>`
3841

3942
## Adding and running `@playwright/test`
4043

41-
You can add `@playwright/test` to this project to get full code completion and run `.spec.js` files for local debugging.
42-
It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/).
44+
Run `npm install` to install all required dependencies.
45+
46+
`@playwright/test` will give you full code completion and run `.spec.js` files for local debugging.
47+
48+
If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/).
4349

4450
```bash
45-
npm install --save-dev @playwright/test@1.38.1
51+
npm install --save-dev @playwright/test@1.54.1
4652
```
4753

4854
## Questions?

examples/advanced-project-js/checkly.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ const config = defineConfig({
4343
* */
4444
testMatch: '**/__checks__/**/*.spec.js',
4545
},
46+
playwrightConfigPath: './playwright.config.js',
47+
playwrightChecks: [
48+
{
49+
logicalId: 'playwright-check-suite',
50+
name: 'Playwright Check Suite JS',
51+
//Use `testCommand: npx playwright test` to filter the tests you want to run
52+
}
53+
],
54+
],
4655
},
4756
cli: {
4857
/* The default datacenter location to use when running npx checkly test */

examples/advanced-project-js/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"author": "",
1111
"license": "ISC",
1212
"devDependencies": {
13-
"checkly": "latest"
13+
"@playwright/test": "^1",
14+
"checkly": "latest",
15+
"jiti": "^1"
1416
}
1517
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { defineConfig, devices } = require('@playwright/test');
2+
const path = require('path');
3+
4+
const AUTH_FILE = '.auth/user.json';
5+
6+
const config = defineConfig({
7+
timeout: 30000,
8+
use: {
9+
baseURL: 'https://www.danube-web.shop',
10+
viewport: { width: 1280, height: 720 },
11+
},
12+
projects: [
13+
{
14+
name: 'login-setup',
15+
testMatch: /.*\.setup.ts/,
16+
use: {
17+
...devices['Desktop Chrome'],
18+
},
19+
},
20+
{
21+
name: 'Firefox',
22+
testDir: './src/tests/',
23+
use: {
24+
...devices['Desktop Firefox'],
25+
storageState: path.resolve(__dirname, AUTH_FILE),
26+
},
27+
dependencies: ["login-setup"],
28+
},
29+
{
30+
name: 'Chromium',
31+
testDir: './src/tests/',
32+
use: {
33+
...devices['Desktop Chrome'],
34+
storageState: path.resolve(__dirname, AUTH_FILE),
35+
// Optionally add Checkly user-agent
36+
userAgent: devices['Desktop Chrome'].userAgent + ' (Checkly, https://www.checklyhq.com)',
37+
},
38+
dependencies: ['login-setup'],
39+
},
40+
]
41+
});
42+
43+
module.exports = config;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test('webshop homepage @homepage', async ({ page }) => {
4+
const response = await page.goto('');
5+
6+
expect(response?.status()).toBeLessThan(400);
7+
await expect(page).toHaveTitle(/Danube WebShop/);
8+
await page.screenshot({ path: 'homepage.jpg' });
9+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { test } = require('@playwright/test');
2+
3+
test('login', {
4+
tag: '@login',
5+
}, async ({ page }) => {
6+
// navigate to our target web page
7+
await page.goto('');
8+
9+
// click on the login button and go through the login procedure
10+
await page.click('#login');
11+
await page.type('#n-email', '[email protected]');
12+
await page.type('#n-password2', 'supersecure1');
13+
await page.click('#goto-signin-btn');
14+
15+
// wait until the login confirmation message is shown
16+
await page.waitForSelector('#login-message', { visible: true });
17+
});

examples/advanced-project/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This example project shows how you can use the Checkly CLI in a monitoring as code (MaC) workflow. We are using the
44
https://checklyhq.com website as a monitoring target.
55

6-
1. Write API Checks and Playwright-powered Browser Checks.
6+
1. Write API Checks and Playwright-powered Browser Checks or fully native Playwright Check Suites.
77
2. Add Alert Channels, and dry-run your Checks on 20+ global locations.
88
3. Test -> Deploy: now you have your app monitored around the clock. All from your code base.
99

@@ -15,6 +15,7 @@ npm create checkly@latest -- --template advanced-project
1515

1616
This project has examples of all Checkly check types and showcases some advanced features. It also adds a GitHub Actions workflow.
1717

18+
- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly.
1819
- Running `npx checkly test` will look for `.check.ts` files and `.spec.ts` in `__checks__` directories and execute them in a dry run.
1920

2021
- Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the
@@ -30,6 +31,7 @@ Run the core CLI commands with `npx checkly <command>`
3031
| Command | Action |
3132
|:---------------------|:-------------------------------------------------|
3233
| `npx checkly test` | Dry run all the checks in your project |
34+
| `npx checkly pw-test`| Run playwright tests in your project |
3335
| `npx checkly deploy` | Deploy your checks to the Checkly cloud |
3436
| `npx checkly login` | Log in to your Checkly account |
3537
| `npx checkly --help` | Show help for each command. |
@@ -38,14 +40,17 @@ Run the core CLI commands with `npx checkly <command>`
3840

3941
## Adding and running `@playwright/test`
4042

41-
You can add `@playwright/test` to this project to get full code completion and run `.spec.ts` files for local debugging.
42-
It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/).
43+
Run `npm install` to install all required dependencies.
44+
45+
`@playwright/test` will give you full code completion and run `.spec.js` files for local debugging.
46+
47+
If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/).
4348

4449
```bash
45-
npm install --save-dev @playwright/test@1.38.1
50+
npm install --save-dev @playwright/test@1.54.1
4651
```
4752

4853
## Questions?
4954

50-
Check [our CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or
55+
Check [the CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or
5156
join our [Slack community](https://checklyhq.com/slack).

examples/advanced-project/checkly.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ const config = defineConfig({
4545
* */
4646
testMatch: '**/__checks__/**/*.spec.ts',
4747
},
48+
49+
// Playwright Check Suites definition, run the whole Playwright Test Suite in a Check
50+
playwrightConfigPath: './playwright.config.ts',
51+
playwrightChecks: [
52+
{
53+
logicalId: 'playwright-check-suite',
54+
name: 'Playwright Check Suite TS',
55+
//Use `testCommand: npx playwright test` to filter the tests you want to run
56+
}
57+
],
4858
},
4959
cli: {
5060
/* The default datacenter location to use when running npx checkly test */

examples/advanced-project/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"author": "",
1111
"license": "ISC",
1212
"devDependencies": {
13+
"@playwright/test": "^1",
1314
"checkly": "latest",
1415
"jiti": "^2"
1516
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { defineConfig, devices } from "@playwright/test"
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
import dotenv from "dotenv"
8+
import path from "path"
9+
dotenv.config({ path: path.resolve(__dirname, ".env") })
10+
11+
export const AUTH_FILE = ".auth/user.json"
12+
13+
/**
14+
* See https://playwright.dev/docs/test-configuration.
15+
*/
16+
17+
export default defineConfig({
18+
timeout: 30000,
19+
use: {
20+
baseURL: "https://www.checklyhq.com",
21+
viewport: { width: 1280, height: 720 },
22+
trace: "on",
23+
24+
},
25+
projects: [
26+
{
27+
name: 'login-setup',
28+
testMatch: /.*\.setup.ts/,
29+
use: {
30+
...devices['Desktop Chrome'],
31+
},
32+
},
33+
{
34+
name: 'Firefox',
35+
testDir: './src/tests/',
36+
use: {
37+
...devices['Desktop Firefox'],
38+
storageState: path.resolve(__dirname, AUTH_FILE),
39+
},
40+
dependencies: ["login-setup"],
41+
},
42+
{
43+
name: 'Chromium',
44+
testDir: './src/tests/',
45+
use: {
46+
...devices['Desktop Chrome'],
47+
storageState: path.resolve(__dirname, AUTH_FILE),
48+
// Optionally add Checkly user-agent
49+
userAgent: `${devices['Desktop Chrome'].userAgent} (Checkly, https://www.checklyhq.com)`,
50+
},
51+
dependencies: ["login-setup"],
52+
},
53+
]
54+
});

0 commit comments

Comments
 (0)