Skip to content

Commit d23ff62

Browse files
committed
Task completion source for events
1 parent 2b3816b commit d23ff62

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextCreatedEvent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public async Task BrowsingContextCreatedEvent()
1313
{
1414
await using var bidi = await driver.AsBidirectionalAsync();
1515

16-
BrowsingContextInfo info = null;
16+
TaskCompletionSource<BrowsingContextInfo> tcs = new();
1717

18-
await bidi.OnBrowsingContextCreatedAsync(e => info = e);
18+
await bidi.OnBrowsingContextCreatedAsync(tcs.SetResult);
1919

2020
driver.SwitchTo().NewWindow(OpenQA.Selenium.WindowType.Window);
2121

22+
var info = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
23+
2224
Assert.IsNotNull(info);
2325
Console.WriteLine(info);
2426
}

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.NavigationStartedEvent.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using OpenQA.Selenium.BiDi;
33
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
4+
using System;
45
using System.Threading.Tasks;
56

67
namespace SeleniumDocs.BiDi.BrowsingContext;
@@ -12,12 +13,14 @@ public async Task NavigationStartedEvent()
1213
{
1314
var browsingContext = await driver.AsBidirectionalContextAsync();
1415

15-
NavigationInfo info = null;
16+
TaskCompletionSource<NavigationInfo> tcs = new();
1617

17-
await browsingContext.OnNavigationStartedAsync(e => info = e);
18+
await browsingContext.OnNavigationStartedAsync(tcs.SetResult);
1819

1920
await browsingContext.NavigateAsync("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html", new() { Wait = ReadinessState.Complete });
2021

22+
var info = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
23+
2124
Assert.IsNotNull(info);
2225
}
2326
}

0 commit comments

Comments
 (0)