From 8603d0e12a4370844ea669759744bebd8fa09b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sat, 1 Jul 2023 09:07:09 -0300 Subject: [PATCH] Improve flaky test logs (#2246) * Improve flaky test logs * Fix another flaky * Docs changes * Add missing value --------- Co-authored-by: GitHub Action --- README.md | 2 +- lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs | 6 ++++-- lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs | 8 ++++++-- lib/PuppeteerSharp/CDPSession.cs | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b2890a028..fde6d8ee5 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf. await page.PdfAsync(outputFile); ``` -snippet source | anchor +snippet source | anchor ### Inject HTML diff --git a/lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs b/lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs index 1254bf3f7..e44c5dbf4 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs @@ -140,15 +140,17 @@ public async Task ShouldKeepTheCallbackClean() // For CI/CD debugging purposes var session = (CDPSession)Page.Client; + var message = "Expected an empty callback list. Found: \n"; + if (session.HasPendingCallbacks()) { foreach(var pendingMessage in session.GetPendingMessages()) { - Console.WriteLine($"Pending message: {pendingMessage.Message}"); + message += $" - {pendingMessage.Message}\n"; } } - Assert.False(((CDPSession)Page.Client).HasPendingCallbacks()); + Assert.False(((CDPSession)Page.Client).HasPendingCallbacks(), message); } } } diff --git a/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs b/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs index 738ce7d68..ddac1ee34 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Threading.Tasks; using Newtonsoft.Json; using PuppeteerSharp.Media; @@ -75,7 +76,10 @@ public async Task CanPrintToPDFAndStreamTheResult() await Page.PdfAsync(outputFile); var stream = await Page.PdfStreamAsync(); - Assert.Equal(new FileInfo(outputFile).Length, stream.Length); + + // Firefox in Linux might generate and of by one result here. + // If the difference is less than 2 bytes is good + Assert.True(Math.Abs(new FileInfo(outputFile).Length - stream.Length) < 2); } [PuppeteerFact] diff --git a/lib/PuppeteerSharp/CDPSession.cs b/lib/PuppeteerSharp/CDPSession.cs index e48443bf7..6f4dd61f3 100644 --- a/lib/PuppeteerSharp/CDPSession.cs +++ b/lib/PuppeteerSharp/CDPSession.cs @@ -76,6 +76,7 @@ public async Task SendAsync(string method, object args = null, bool wai { TaskWrapper = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), Method = method, + Message = message, }; _callbacks[id] = callback; }