diff --git a/lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs b/lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs index da9cc5e51..ce0ec5ec1 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; +using PuppeteerSharp.Helpers; namespace PuppeteerSharp.Tests.PageTests { @@ -64,14 +65,21 @@ public async Task ShouldContainRefererHeader() { await Page.SetRequestInterceptionAsync(true); var requests = new List(); + var requestsReadyTcs = new TaskCompletionSource(); Page.Request += async (sender, e) => { await e.Request.ContinueAsync(); requests.Add(e.Request); + + if (requests.Count > 1) + { + requestsReadyTcs.TrySetResult(true); + } }; await Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html"); + await requestsReadyTcs.Task.WithTimeout(); Assert.Contains("/one-style.css", requests[1].Url); Assert.Contains("/one-style.html", requests[1].Headers["Referer"]); }