Skip to content

Commit b7032c2

Browse files
authored
cherry-pick(#36350): fix(trace): include method into "Fetch" action title (#36352)
1 parent e0d1741 commit b7032c2

File tree

8 files changed

+28
-25
lines changed

8 files changed

+28
-25
lines changed

packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// This file is generated by generate_channels.js, do not edit manually.
1818

1919
export const methodMetainfo = new Map<string, { internal?: boolean, title?: string, slowMo?: boolean, snapshot?: boolean, pausesBeforeInput?: boolean }>([
20-
['APIRequestContext.fetch', { title: 'Fetch "{url}"', }],
20+
['APIRequestContext.fetch', { title: '{method} "{url}"', }],
2121
['APIRequestContext.fetchResponseBody', { internal: true, }],
2222
['APIRequestContext.fetchLog', { internal: true, }],
2323
['APIRequestContext.storageState', { internal: true, }],

packages/protocol/src/protocol.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ APIRequestContext:
362362
commands:
363363

364364
fetch:
365-
title: Fetch "{url}"
365+
title: '{method} "{url}"'
366366
parameters:
367367
url: string
368368
encodedParams: string?

packages/trace-viewer/src/ui/actionList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ export function renderTitleForCall(action: ActionTraceEvent): { elements: React.
164164
title.push(chunk);
165165

166166
const param = formatProtocolParam(action.params, quotedText);
167-
elements.push(<span className='action-title-param'>{param}</span>);
167+
if (match.index === 0)
168+
elements.push(param);
169+
else
170+
elements.push(<span className='action-title-param'>{param}</span>);
168171
title.push(param);
169172
currentIndex = match.index + fullMatch.length;
170173
}

tests/library/trace-viewer.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,16 +1053,16 @@ test('should open two trace files', async ({ context, page, request, server, sho
10531053

10541054
const traceViewer = await showTraceViewer([contextTrace, apiTrace]);
10551055

1056-
await traceViewer.selectAction('FETCH', 0);
1057-
await traceViewer.selectAction('FETCH', 1);
1058-
await traceViewer.selectAction('FETCH', 2);
1056+
await traceViewer.selectAction('GET');
1057+
await traceViewer.selectAction('HEAD');
1058+
await traceViewer.selectAction('POST');
10591059
await expect(traceViewer.actionTitles).toHaveText([
1060-
/Fetch "\/simple\.json"/,
1060+
/GET "\/simple\.json"/,
10611061
/Navigate to "\/input\/button\.html"/,
1062-
/Fetch "\/simplezip\.json"/,
1062+
/HEAD "\/simplezip\.json"/,
10631063
/Click.*locator\('button'\)/,
10641064
/Click.*locator\('button'\)/,
1065-
/Fetch "\/one-style\.css"/,
1065+
/POST "\/one-style\.css"/,
10661066
]);
10671067

10681068
await traceViewer.page.locator('text=Metadata').click();

tests/library/tracing.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test('should include context API requests', async ({ context, page, server }, te
165165
await page.request.post(server.PREFIX + '/simple.json', { data: { foo: 'bar' } });
166166
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
167167
const { events, actions } = await parseTraceRaw(testInfo.outputPath('trace.zip'));
168-
expect(actions).toContain('Fetch "/simple.json"');
168+
expect(actions).toContain('POST "/simple.json"');
169169
const harEntry = events.find(e => e.type === 'resource-snapshot');
170170
expect(harEntry).toBeTruthy();
171171
expect(harEntry.snapshot.request.url).toBe(server.PREFIX + '/simple.json');

tests/playwright-test/playwright.trace.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {
9898
' Fixture "page"',
9999
' Create page',
100100
'Navigate to "about:blank"',
101-
'Fetch "/empty.html"',
101+
'GET "/empty.html"',
102102
'After Hooks',
103103
' Fixture "page"',
104104
' Fixture "context"',
@@ -108,7 +108,7 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {
108108
expect(trace2.actionTree).toEqual([
109109
'Before Hooks',
110110
'Create request context',
111-
'Fetch "/empty.html"',
111+
'GET "/empty.html"',
112112
'After Hooks',
113113
]);
114114
const trace3 = await parseTrace(testInfo.outputPath('test-results', 'a-fail', 'trace.zip'));
@@ -121,7 +121,7 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {
121121
' Fixture "page"',
122122
' Create page',
123123
'Navigate to "about:blank"',
124-
'Fetch "/empty.html"',
124+
'GET "/empty.html"',
125125
'Expect "toBe"',
126126
'After Hooks',
127127
' Fixture "page"',
@@ -328,7 +328,7 @@ test('should not override trace file in afterAll', async ({ runInlineTest, serve
328328
' afterAll hook',
329329
' Fixture "request"',
330330
' Create request context',
331-
' Fetch "/empty.html"',
331+
' GET "/empty.html"',
332332
' Fixture "request"',
333333
'Worker Cleanup',
334334
' Fixture "browser"',
@@ -506,7 +506,7 @@ test(`trace:retain-on-failure should create trace if request context is disposed
506506
}, { trace: 'retain-on-failure' });
507507
const tracePath = test.info().outputPath('test-results', 'a-passing-test', 'trace.zip');
508508
const trace = await parseTrace(tracePath);
509-
expect(trace.titles).toContain('Fetch "/empty.html"');
509+
expect(trace.titles).toContain('GET "/empty.html"');
510510
expect(result.failed).toBe(1);
511511
});
512512

@@ -1155,7 +1155,7 @@ test('trace:retain-on-first-failure should create trace if request context is di
11551155
}, { trace: 'retain-on-first-failure' });
11561156
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
11571157
const trace = await parseTrace(tracePath);
1158-
expect(trace.titles).toContain('Fetch "/empty.html"');
1158+
expect(trace.titles).toContain('GET "/empty.html"');
11591159
expect(result.failed).toBe(1);
11601160
});
11611161

@@ -1261,7 +1261,7 @@ test('should not nest top level expect into unfinished api calls ', {
12611261
' Fixture "page"',
12621262
' Create page',
12631263
'Navigate to "/index"',
1264-
'Fetch "/hang"',
1264+
'GET "/hang"',
12651265
'Expect "toBeVisible"',
12661266
'After Hooks',
12671267
' Fixture "page"',

tests/playwright-test/reporter-html.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
612612
await page.click('text=Source');
613613
await expect(page.locator('.source-line-running')).toContainText('page.evaluate');
614614

615-
await page.click('.action-title >> text=FETCH');
615+
await page.click('.action-title >> text=GET');
616616
await page.click('text=Source');
617617
await expect(page.locator('.source-line-running')).toContainText('request.get');
618618
});
@@ -643,10 +643,10 @@ for (const useIntermediateMergeReport of [true, false] as const) {
643643
await page.getByRole('link', { name: 'View Trace' }).click();
644644

645645
// Trace viewer should not hang here when displaying parallal requests.
646-
await expect(page.getByTestId('actions-tree')).toContainText('Fetch');
647-
await page.getByText('Fetch').nth(2).click();
648-
await page.getByText('Fetch').nth(1).click();
649-
await page.getByText('Fetch').nth(0).click();
646+
await expect(page.getByTestId('actions-tree')).toContainText('GET');
647+
await page.getByText('GET').nth(2).click();
648+
await page.getByText('GET').nth(1).click();
649+
await page.getByText('GET').nth(0).click();
650650
});
651651

652652
test('should warn user when viewing via file:// protocol', async ({ runInlineTest, page, showReport }, testInfo) => {

tests/playwright-test/test-step.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,9 @@ pw:api |Wait for navigation @ a.test.ts:5
12181218
pw:api |Navigate to "data:" @ a.test.ts:6
12191219
pw:api |Click locator('button') @ a.test.ts:8
12201220
pw:api |Click getByRole('button') @ a.test.ts:9
1221-
pw:api |Fetch "/empty.html" @ a.test.ts:10
1221+
pw:api |GET "/empty.html" @ a.test.ts:10
12221222
pw:api |↪ error: <error message>
1223-
pw:api |Fetch "/empty.html" @ a.test.ts:11
1223+
pw:api |GET "/empty.html" @ a.test.ts:11
12241224
pw:api |↪ error: <error message>
12251225
hook |After Hooks
12261226
fixture | request
@@ -1515,7 +1515,7 @@ fixture | page
15151515
pw:api | Create page
15161516
test.step |custom step @ a.test.ts:4
15171517
pw:api | Navigate to "/empty.html" @ a.test.ts:12
1518-
pw:api | Fetch "/empty.html" @ a.test.ts:6
1518+
pw:api | GET "/empty.html" @ a.test.ts:6
15191519
expect | toBe @ a.test.ts:8
15201520
hook |After Hooks
15211521
fixture | page

0 commit comments

Comments
 (0)