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(har): `APIRequestContext` cookie expires should be in ms (#41482)
Devin Roussoee02af885fa4
diff --git a/packages/playwright-core/src/server/har/harTracer.ts b/packages/playwright-core/src/server/har/harTracer.tsindex b461d4189e..c888a33307 100644--- a/packages/playwright-core/src/server/har/harTracer.ts+++ b/packages/playwright-core/src/server/har/harTracer.ts@@ -256,7 +256,7 @@ export class HarTracer {harEntry.response.cookies = this._options.omitCookies ? [] : event.cookies.map(c => {return {...c,- expires: c.expires === -1 ? undefined : safeDateToISOString(c.expires)+ expires: c.expires === -1 ? undefined : safeDateToISOString(c.expires * 1000)};});diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.tsindex 6550c5bc79..e3b11c77d4 100644--- a/tests/library/har.spec.ts+++ b/tests/library/har.spec.ts@@ -1103,6 +1103,25 @@ it.describe('tracing.startHar', () => {expect(log.entries.some(e => e.request.url === server.PREFIX + '/simple.json')).toBe(true);});+ it('should record correct cookie expires for APIRequestContext', async ({ playwright, server }, testInfo) => {+ server.setRoute('/set-cookie', (req, res) => {+ res.setHeader('Set-Cookie', 'name=value; Expires=Tue, 01 Jan 2030 00:00:00 GMT');+ res.end('hello');+ });+ const request = await playwright.request.newContext();+ const harPath = testInfo.outputPath('api.har.zip');+ await request.tracing.startHar(harPath, { content: 'attach' });+ await request.get(server.PREFIX + '/set-cookie');+ await request.tracing.stopHar();+ await request.dispose();++ const resources = await parseHar(harPath);+ const log = JSON.parse(resources.get('har.har')!.toString()).log as Log;+ const entry = log.entries.find(e => e.request.url.endsWith('/set-cookie'))!;+ const cookie = entry.response.cookies.find(c => c.name === 'name')!;+ expect(new Date(cookie.expires!).getUTCFullYear()).toBe(2030);+ });+it('should record mixed-case request content-type for APIRequestContext', async ({ playwright, server }, testInfo) => {server.setRoute('/post', (req, res) => res.end('ok'));const request = await playwright.request.newContext();