-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
ui-mode-test-network-tab.spec.ts
162 lines (131 loc) · 5.65 KB
/
ui-mode-test-network-tab.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect, test } from './ui-mode-fixtures';
test('should filter network requests by resource type', async ({ runUITest, server }) => {
server.setRoute('/api/endpoint', (_, res) => res.setHeader('Content-Type', 'application/json').end());
const { page } = await runUITest({
'network-tab.test.ts': `
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
});
`,
});
await page.getByText('network tab test').dblclick();
await page.getByText('Network', { exact: true }).click();
const networkItems = page.getByTestId('network-list').getByRole('listitem');
await page.getByText('JS', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('script.js')).toBeVisible();
await page.getByText('CSS', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('style.css')).toBeVisible();
await page.getByText('Image', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('image.png')).toBeVisible();
await page.getByText('Fetch', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('endpoint')).toBeVisible();
await page.getByText('HTML', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('network.html')).toBeVisible();
await page.getByText('Font', { exact: true }).click();
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('font.woff2')).toBeVisible();
});
test('should filter network requests by url', async ({ runUITest, server }) => {
const { page } = await runUITest({
'network-tab.test.ts': `
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
});
`,
});
await page.getByText('network tab test').dblclick();
await page.getByText('Network', { exact: true }).click();
const networkItems = page.getByTestId('network-list').getByRole('listitem');
await page.getByPlaceholder('Filter network').fill('script.');
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('script.js')).toBeVisible();
await page.getByPlaceholder('Filter network').fill('png');
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('image.png')).toBeVisible();
await page.getByPlaceholder('Filter network').fill('api/');
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('endpoint')).toBeVisible();
await page.getByPlaceholder('Filter network').fill('End');
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('endpoint')).toBeVisible();
await page.getByPlaceholder('Filter network').fill('FON');
await expect(networkItems).toHaveCount(1);
await expect(networkItems.getByText('font.woff2')).toBeVisible();
});
test('should format JSON request body', async ({ runUITest, server }) => {
const { page } = await runUITest({
'network-tab.test.ts': `
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
});
`,
});
await page.getByText('network tab test').dblclick();
await page.getByText('Network', { exact: true }).click();
await page.getByText('post-data-1').click();
await expect(page.locator('.CodeMirror-code .CodeMirror-line').allInnerTexts()).resolves.toEqual([
'{',
' "data": {',
' "key": "value",',
' "array": [',
' "value-1",',
' "value-2"',
' ]',
' }',
'}',
]);
await page.getByText('post-data-2').click();
await expect(page.locator('.CodeMirror-code .CodeMirror-line').allInnerTexts()).resolves.toEqual([
'{',
' "data": {',
' "key": "value",',
' "array": [',
' "value-1",',
' "value-2"',
' ]',
' }',
'}',
]);
});
test('should display list of query parameters (only if present)', async ({ runUITest, server }) => {
const { page } = await runUITest({
'network-tab.test.ts': `
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
});
`,
});
await page.getByText('network tab test').dblclick();
await page.getByText('Network', { exact: true }).click();
await page.getByText('call-with-query-params').click();
await expect(page.getByText('Query String Parameters')).toBeVisible();
await expect(page.getByText('param1: value1')).toBeVisible();
await expect(page.getByText('param1: value2')).toBeVisible();
await expect(page.getByText('param2: value2')).toBeVisible();
await page.getByText('endpoint').click();
await expect(page.getByText('Query String Parameters')).not.toBeVisible();
});