Repository: microsoft/playwright
File: tests/library/browsercontext-har.spec.ts (TypeScript)

Code before:

it('should record single set-cookie headers', {
  annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31495' }
}, async ({ contextFactory, server }, testInfo) => {
  server.setRoute('/empty.html', (req, res) => {
    res.setHeader('Content-Type', 'text/html');
    res.setHeader('set-cookie', ['first=foo']);
    res.end();
  });

  const harPath = testInfo.outputPath('har.zip');
  console.log('HAR path:', harPath);
  const context1 = await contextFactory();
  await context1.routeFromHAR(harPath, { update: true });
  const page1 = await context1.newPage();
  await page1.goto(server.EMPTY_PAGE);
  const cookie1 = await page1.evaluate(() => document.cookie);
  expect(cookie1.split('; ').sort().join('; ')).toBe('first=foo');
  await context1.close();

  const context2 = await contextFactory();
  await context2.routeFromHAR(harPath, { notFound: 'abort' });
  const page2 = await context2.newPage();
  await page2.goto(server.EMPTY_PAGE);
  const cookie2 = await page2.evaluate(() => document.cookie);
  expect(cookie2.split('; ').sort().join('; ')).toBe('first=foo');
});

it('should record multiple set-cookie headers', {
  annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31495' }
}, async ({ contextFactory, server }, testInfo) => {
  server.setRoute('/empty.html', (req, res) => {
    res.setHeader('Content-Type', 'text/html');
    res.setHeader('set-cookie', ['first=foo', 'second=bar']);
    res.end();
  });

  const harPath = testInfo.outputPath('har.zip');
  console.log('HAR path:', harPath);
  const context1 = await contextFactory();
  await context1.routeFromHAR(harPath, { update: true });
  const page1 = await context1.newPage();
  await page1.goto(server.EMPTY_PAGE);
  const cookie1 = await page1.evaluate(() => document.cookie);
  expect(cookie1.split('; ').sort().join('; ')).toBe('first=foo; second=bar');
  await context1.close();

  const context2 = await contextFactory();
  await context2.routeFromHAR(harPath, { notFound: 'abort' });
  const page2 = await context2.newPage();
  await page2.goto(server.EMPTY_PAGE);

Review comment (suggestion):
```suggestion
  expect(cookie2).toBe('first=foo');
```

Code after:
  });

  const harPath = testInfo.outputPath('har.zip');
  const context1 = await contextFactory();
  await context1.routeFromHAR(harPath, { update: true });
  const page1 = await context1.newPage();
  await page1.goto(server.EMPTY_PAGE);
  const cookie1 = await page1.evaluate(() => document.cookie);
  expect(cookie1).toBe('first=foo');
  await context1.close();

  const context2 = await contextFactory();
  await context2.routeFromHAR(harPath, { notFound: 'abort' });
  const page2 = await context2.newPage();
  await page2.goto(server.EMPTY_PAGE);
  const cookie2 = await page2.evaluate(() => document.cookie);
  expect(cookie2).toBe('first=foo');
});

it('should record multiple set-cookie headers', {
  annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31495' }
}, async ({ contextFactory, server }, testInfo) => {
  server.setRoute('/empty.html', (req, res) => {
    res.setHeader('Content-Type', 'text/html');
    res.setHeader('set-cookie', ['first=foo', 'second=bar']);
    res.end();
  });

  const harPath = testInfo.outputPath('har.zip');
  const context1 = await contextFactory();
  await context1.routeFromHAR(harPath, { update: true });
  const page1 = await context1.newPage();
  await page1.goto(server.EMPTY_PAGE);
  const cookie1 = await page1.evaluate(() => document.cookie);
  expect(cookie1.split('; ').sort().join('; ')).toBe('first=foo; second=bar');
  await context1.close();

  const context2 = await contextFactory();
  await context2.routeFromHAR(harPath, { notFound: 'abort' });
  const page2 = await context2.newPage();
  await page2.goto(server.EMPTY_PAGE);
  const cookie2 = await page2.evaluate(() => document.cookie);
  expect(cookie2.split('; ').sort().join('; ')).toBe('first=foo; second=bar');
});


it('should update har.zip for page', async ({ contextFactory, server }, testInfo) => {
  const harPath = testInfo.outputPath('har.zip');
  const context1 = await contextFactory();
  const page1 = await context1.newPage();
  await page1.routeFromHAR(harPath, { update: true });