playwright/tests/playwright-test/ui-mode-test-network-tab.spec.ts
Kuba Janik a6b320e362
fix(ui-mode): format request body when headers are lower case (#32395)
Resolves https://github.com/microsoft/playwright/issues/32396

Currently, the request body is not formatted when content type header is
lower case (`content-type`). Even though the value is
`application/json`.

It happens because we are looking only for `Content-Type` header
ignoring headers that are lower case.

<img width="674" alt="363197933-5178ec23-b9cf-46b5-8284-e8d4d730b036"
src="https://github.com/user-attachments/assets/0ef01b52-7dd8-4f33-b836-9adb86f94cc9">
2024-08-30 16:21:51 +02:00

138 lines
4.7 KiB
TypeScript

/**
* 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"',
' ]',
' }',
'}',
]);
});