From 73d863415dcbc289e888d7cce5691e2dc4baf711 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 21 Jul 2025 11:16:27 -0700 Subject: [PATCH] chore: unflake tracing test Same as https://github.com/microsoft/playwright/pull/36612 --- .../com/microsoft/playwright/TestChromiumTracing.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/playwright/src/test/java/com/microsoft/playwright/TestChromiumTracing.java b/playwright/src/test/java/com/microsoft/playwright/TestChromiumTracing.java index 93d1a220c..10c88b7d8 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestChromiumTracing.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestChromiumTracing.java @@ -57,6 +57,13 @@ void shouldCreateDirectoriesAsNeeded(@TempDir Path tempDir) { } } + private static void rafraf(Page page) { + int count = 2; + for (int i = 0; i < count; i++) { + page.evaluate("() => new Promise(f => requestAnimationFrame(() => requestAnimationFrame(f)))"); + } + } + @Test void shouldRunWithCustomCategoriesIfProvided(@TempDir Path tempDir) throws IOException { try (Page page = browser.newPage()) { @@ -64,7 +71,7 @@ void shouldRunWithCustomCategoriesIfProvided(@TempDir Path tempDir) throws IOExc browser.startTracing(page, new Browser.StartTracingOptions() .setPath(outputTraceFile) .setCategories(asList("disabled-by-default-cc.debug"))); - page.evaluate("() => 1 + 1"); + rafraf(page); browser.stopTracing(); try (FileReader fileReader = new FileReader(outputTraceFile.toFile())) { JsonObject traceJson = new Gson().fromJson(fileReader, JsonObject.class); @@ -75,7 +82,7 @@ void shouldRunWithCustomCategoriesIfProvided(@TempDir Path tempDir) throws IOExc boolean hasTraceEvents = traceJson.getAsJsonArray("traceEvents").asList().stream() .anyMatch(event -> { JsonObject eventObj = (JsonObject) event; - return eventObj.has("cat") && + return eventObj.has("cat") && eventObj.get("cat").getAsString().equals("disabled-by-default-cc.debug"); }); assertTrue(hasTraceConfig || hasTraceEvents);