Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: fix flaky cookie roundtrip test (#19459)

Ross Wollmana1bb1dd94f12
diff --git a/tests/library/browsercontext-add-cookies.spec.ts b/tests/library/browsercontext-add-cookies.spec.ts
index 549bf8f148..b91b133276 100644
--- a/tests/library/browsercontext-add-cookies.spec.ts
+++ b/tests/library/browsercontext-add-cookies.spec.ts
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+import type { Cookie } from '@playwright/test';
import { contextTest as it, playwrightTest, expect } from '../config/browserTest';
it('should work @smoke', async ({ context, page, server }) => {
@@ -77,7 +78,9 @@ it('should roundtrip cookie', async ({ context, page, server }) => {
await context.clearCookies();
expect(await context.cookies()).toEqual([]);
await context.addCookies(cookies);
- expect(await context.cookies()).toEqual(cookies);
+ // Slightly different rounding on chromium win.
+ const normalizedExpires = (cookies: Cookie[]) => cookies.map(c => ({ ...c, expires: Math.floor(c.expires) }));
+ expect(normalizedExpires(await context.cookies())).toEqual(normalizedExpires(cookies));
});
it('should send cookie header', async ({ server, context }) => {