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
fix: fix har entry time calculation (#6472)
Anx1c10c4cbe818
diff --git a/src/server/supplements/har/harTracer.ts b/src/server/supplements/har/harTracer.tsindex 6010c4d6f6..a3d99e51cb 100644--- a/src/server/supplements/har/harTracer.ts+++ b/src/server/supplements/har/harTracer.ts@@ -186,14 +186,20 @@ export class HarTracer {const timing = response.timing();if (pageEntry.startedDateTime.valueOf() > timing.startTime)pageEntry.startedDateTime = new Date(timing.startTime);+ const dns = timing.domainLookupEnd !== -1 ? helper.millisToRoundishMillis(timing.domainLookupEnd - timing.domainLookupStart) : -1;+ const connect = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1;+ const ssl = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1;+ const wait = timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1;+ const receive = response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1;harEntry.timings = {- dns: timing.domainLookupEnd !== -1 ? helper.millisToRoundishMillis(timing.domainLookupEnd - timing.domainLookupStart) : -1,- connect: timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1,- ssl: timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1,+ dns,+ connect,+ ssl,send: 0,- wait: timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1,- receive: response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1,+ wait,+ receive,};+ harEntry.time = [dns, connect, ssl, wait, receive].reduce((pre, cur) => cur > 0 ? cur + pre : pre, 0);if (!this._options.omitContent && response.status() === 200) {const promise = response.body().then(buffer => {harEntry.response.content.text = buffer.toString('base64');diff --git a/tests/har.spec.ts b/tests/har.spec.tsindex f620045feb..04b638064a 100644--- a/tests/har.spec.ts+++ b/tests/har.spec.ts@@ -251,3 +251,10 @@ it('should include content', async ({ contextFactory, server }, testInfo) => {expect(content2.mimeType).toBe('text/css; charset=utf-8');expect(Buffer.from(content2.text, 'base64').toString()).toContain('pink');});++it('should calculate time', async ({ contextFactory, server }, testInfo) => {+ const { page, getLog } = await pageWithHar(contextFactory, testInfo);+ await page.goto(server.PREFIX + '/har.html');+ const log = await getLog();+ expect(log.entries[0].time).toBeGreaterThan(0);+});