private Task WaitForURLAsync(string urlString, Regex urlRegex, Func <string, bool> urlFunc, float?timeout, WaitUntilState waitUntil) { if (UrlMatches(Url, urlString, urlRegex, urlFunc)) { return(WaitForLoadStateAsync(waitUntil.EnsureDefaultValue(WaitUntilState.Load).ToLoadState(), timeout)); } return(WaitForNavigationAsync(urlString, urlRegex, urlFunc, waitUntil, timeout)); }
internal async Task <IResponse> WaitForNavigationAsync( string urlString, Regex urlRegex, Func <string, bool> urlFunc, WaitUntilState waitUntil, float?timeout) { waitUntil = waitUntil.EnsureDefaultValue(WaitUntilState.Load); var waiter = SetupNavigationWaiter(timeout); string toUrl = !string.IsNullOrEmpty(urlString) ? $" to \"{urlString}\"" : string.Empty; waiter.Log($"waiting for navigation{toUrl} until \"{waitUntil}\""); var navigatedEvent = await waiter.WaitForEventAsync <FrameNavigatedEventArgs>( this, "Navigated", e => { // Any failed navigation results in a rejection. if (e.Error != null) { return(true); } waiter.Log($" navigated to \"{e.Url}\""); return(UrlMatches(e.Url, urlString, urlRegex, urlFunc)); }).ConfigureAwait(false); if (navigatedEvent.Error != null) { var ex = new NavigationException(navigatedEvent.Error); var tcs = new TaskCompletionSource <bool>(); tcs.TrySetException(ex); await waiter.WaitForPromiseAsync(tcs.Task).ConfigureAwait(false); } if (!_loadStates.Select(s => s.ToValueString()).Contains(waitUntil.ToValueString())) { await waiter.WaitForEventAsync <LoadState>( this, "LoadState", e => { waiter.Log($" \"{e}\" event fired"); return(e.ToValueString() == waitUntil.ToValueString()); }).ConfigureAwait(false); } var request = navigatedEvent.NewDocument?.Request?.Object; var response = request != null ? await waiter.WaitForPromiseAsync(request.FinalRequest.ResponseAsync()).ConfigureAwait(false) : null; waiter.Dispose(); return(response); }
/// <inheritdoc /> public Task SetContentAsync(string html, float?timeout, WaitUntilState waitUntil) => SetContentAsync(false, html, waitUntil.EnsureDefaultValue(WaitUntilState.Load), timeout);
/// <inheritdoc /> public Task <IResponse> GoToAsync(string url, WaitUntilState waitUntil, float?timeout, string referer) => GoToAsync(false, url, waitUntil.EnsureDefaultValue(WaitUntilState.Load), referer, timeout);