static async Task Clicks(BlazorClient client) { var batch = await client.ExpectRenderBatch(() => client.NavigateAsync(ServerUrl + "/home")); if (!client.Hive.TryFindElementById("changeState", out var changeState)) { throw new InvalidOperationException($"Expected to have navigated to the home page."); } client.Hive.TryFindElementById("state", out var state); await changeState.ClickAsync(client.HubConnection); await client.PrepareForNextBatch(null); if (state.Attributes["data-state"].ToString() == "Clicked") { Console.WriteLine("State changed to clicked."); } else { throw new InvalidOperationException("State was not 'Clicked'."); } await client.ExpectRenderBatch(() => changeState.DoubleClickAsync(client.HubConnection)); if (state.Attributes["data-state"].ToString() == "DoubleClicked") { Console.WriteLine("State changed to dblclicked."); } else { throw new InvalidOperationException("State was not 'DoubleClicked'."); } }
public static async Task ExistsAsync(this BlazorClient client, string id, TimeSpan?timeout = default) { timeout ??= TimeSpan.FromSeconds(3); var cts = new CancellationTokenSource(timeout.Value); while (!cts.IsCancellationRequested) { if (client.Hive.TryFindElementById(id, out _)) { return; } await client.PrepareForNextBatch(timeout); } throw new TimeoutException($"Unable to find element with id {id} in {timeout.Value} duration."); }