-
Notifications
You must be signed in to change notification settings - Fork 5
/
home.spec.ts
84 lines (67 loc) · 2.59 KB
/
home.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { test, expect } from '@playwright/test';
import Tracetest, { Types } from '@tracetest/playwright';
const { TRACETEST_API_TOKEN = '', TRACETEST_SERVER_URL = 'https://app.tracetest.io' } = process.env;
let tracetest: Types.TracetestPlaywright | undefined = undefined;
test.describe.configure({ mode: 'serial' });
const definition = `
type: Test
spec:
id: UGxheXdyaWdodDogaW1wb3J0cyBhIHBva2Vtb24=
name: "Playwright: imports a pokemon"
trigger:
type: playwright
specs:
- selector: span[tracetest.span.type="http"]
name: "All HTTP Spans: Status code is 200"
assertions:
- attr:http.status_code = 200
- selector: span[tracetest.span.type="database"]
name: "All Database Spans: Processing time is less than 100ms"
assertions:
- attr:tracetest.span.duration < 2s
outputs:
- name: MY_OUTPUT
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
value: attr:name
`;
test.beforeAll(async () => {
tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN, serverUrl: TRACETEST_SERVER_URL, serverPath: '' });
await tracetest.setOptions({
'Playwright: imports a pokemon': {
definition,
},
});
});
test.beforeEach(async ({ page }, info) => {
await page.goto('/');
await tracetest?.capture(page, info);
});
// optional step to break the playwright script in case a Tracetest test fails
test.afterAll(async ({}, testInfo) => {
testInfo.setTimeout(80000);
await tracetest?.summary();
});
test('Playwright: creates a pokemon', async ({ page }) => {
expect(await page.getByText('Pokeshop')).toBeTruthy();
await page.click('text=Add');
await page.getByLabel('Name').fill('Charizard');
await page.getByLabel('Type').fill('Flying');
await page
.getByLabel('Image URL')
.fill('https://upload.wikimedia.org/wikipedia/en/1/1f/Pok%C3%A9mon_Charizard_art.png');
await page.getByRole('button', { name: 'OK', exact: true }).click();
});
test('Playwright: imports a pokemon', async ({ page }) => {
expect(await page.getByText('Pokeshop')).toBeTruthy();
await page.click('text=Import');
await page.getByLabel('ID').fill('143');
await Promise.all([
page.waitForResponse(resp => resp.url().includes('/pokemon/import') && resp.status() === 200),
page.getByRole('button', { name: 'OK', exact: true }).click(),
]);
});
test('Playwright: deletes a pokemon', async ({ page }) => {
await page.locator('[data-cy="pokemon-list"]');
await page.locator('[data-cy="pokemon-card"]').first().click();
await page.locator('[data-cy="pokemon-card"] [data-cy="delete-pokemon-button"]').first().click();
});