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

Code before:
  await page2.goto(server.PREFIX + '/empty.html');
  const requestPromise = page2.waitForRequest(/.*form.html/);
  await page2.locator('button').click();
  const request = await requestPromise;
  expect.soft(await request.response()).toBeTruthy();
  expect(request.failure()).toBe(null);
  await expect(page2.locator('div')).toHaveText('done');
});

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);

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

Code after:

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');
  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');