Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(har): add _requestref (#8847)
Ross Wollman549411dc33a7
diff --git a/src/server/supplements/har/har.ts b/src/server/supplements/har/har.tsindex d8d21a23a6..2e003b9bbe 100644--- a/src/server/supplements/har/har.ts+++ b/src/server/supplements/har/har.ts@@ -55,6 +55,7 @@ export type Entry = {timings: Timings;serverIPAddress?: string;connection?: string;+ _requestref: string;_frameref: string;_monotonicTime: number;_serverPort?: number;diff --git a/src/server/supplements/har/harTracer.ts b/src/server/supplements/har/harTracer.tsindex 2390c5607d..88b8f7d776 100644--- a/src/server/supplements/har/harTracer.ts+++ b/src/server/supplements/har/harTracer.ts@@ -141,6 +141,7 @@ export class HarTracer {const pageEntry = this._ensurePageEntry(page);const harEntry: har.Entry = {pageref: pageEntry.id,+ _requestref: request.guid,_frameref: request.frame().guid,_monotonicTime: monotonicTime(),startedDateTime: new Date(),diff --git a/tests/har.spec.ts b/tests/har.spec.tsindex 8a9dd45ba2..f4c0871458 100644--- a/tests/har.spec.ts+++ b/tests/har.spec.ts@@ -589,3 +589,42 @@ it('should have different hars for concurrent contexts', async ({ contextFactoryexpect(pageEntry.title).toBe('One');}});++it('should include _requestref', async ({ contextFactory, server }, testInfo) => {+ const { page, getLog } = await pageWithHar(contextFactory, testInfo);+ const resp = await page.goto(server.EMPTY_PAGE);+ const log = await getLog();+ expect(log.entries.length).toBe(1);+ const entry = log.entries[0];+ expect(entry._requestref).toMatch(/^request@[a-f0-9]{32}$/);+ expect(entry._requestref).toBe((resp.request() as any)._guid);+});++it('should include _requestref for redirects', async ({ contextFactory, server }, testInfo) => {+ server.setRedirect('/start', '/one-more');+ server.setRedirect('/one-more', server.EMPTY_PAGE);++ const { page, getLog, context } = await pageWithHar(contextFactory, testInfo);++ const requests = new Map<string, string>();+ context.on('request', request => {+ requests.set(request.url(), (request as any)._guid);+ });++ await page.goto(server.PREFIX + '/start');++ const log = await getLog();+ expect(log.entries.length).toBe(3);++ const entryStart = log.entries[0];+ expect(entryStart.request.url).toBe(server.PREFIX + '/start');+ expect(entryStart._requestref).toBe(requests.get(entryStart.request.url));++ const entryOneMore = log.entries[1];+ expect(entryOneMore.request.url).toBe(server.PREFIX + '/one-more');+ expect(entryOneMore._requestref).toBe(requests.get(entryOneMore.request.url));++ const entryEmptyPage = log.entries[2];+ expect(entryEmptyPage.request.url).toBe(server.EMPTY_PAGE);+ expect(entryEmptyPage._requestref).toBe(requests.get(entryEmptyPage.request.url));+});