diff --git a/src/Playwright/Core/APIRequestContext.cs b/src/Playwright/Core/APIRequestContext.cs index 6840330dc..ecab4cb3a 100644 --- a/src/Playwright/Core/APIRequestContext.cs +++ b/src/Playwright/Core/APIRequestContext.cs @@ -147,7 +147,6 @@ public async Task FetchAsync(string url, APIRequestContextOptions? ["ignoreHTTPSErrors"] = options?.IgnoreHTTPSErrors, ["maxRedirects"] = options?.MaxRedirects, ["maxRetries"] = options?.MaxRetries, - ["timeout"] = _timeoutSettings.Timeout(options?.Timeout), ["params"] = options?.Params?.ToDictionary(x => x.Key, x => x.Value.ToString()).ToProtocol(), ["encodedParams"] = options?.ParamsString, ["headers"] = options?.Headers?.ToProtocol(), @@ -157,7 +156,7 @@ public async Task FetchAsync(string url, APIRequestContextOptions? ["multipartData"] = (options?.Multipart as FormData)?.ToProtocol(), }; - var response = await SendMessageToServerAsync("fetch", message).ConfigureAwait(false); + var response = await SendMessageToServerAsync("fetch", message, timeout: _timeoutSettings.Timeout(options?.Timeout)).ConfigureAwait(false); return new APIResponse(this, response?.GetProperty("response").ToObject()!); } diff --git a/src/Playwright/Core/BrowserType.cs b/src/Playwright/Core/BrowserType.cs index 08f7fcb03..e8fb0e423 100644 --- a/src/Playwright/Core/BrowserType.cs +++ b/src/Playwright/Core/BrowserType.cs @@ -74,8 +74,8 @@ public async Task LaunchAsync(BrowserTypeLaunchOptions? options = defa { "firefoxUserPrefs", options.FirefoxUserPrefs }, { "chromiumSandbox", options.ChromiumSandbox }, { "slowMo", options.SlowMo }, - { "timeout", TimeoutSettings.LaunchTimeout(options.Timeout) }, - }).ConfigureAwait(false); + }, + timeout: TimeoutSettings.LaunchTimeout(options.Timeout)).ConfigureAwait(false); browser.ConnectToBrowserType(this, options.TracesDir); return browser; } @@ -100,7 +100,6 @@ public async Task LaunchPersistentContextAsync(string userDataD ["handleSIGINT"] = options.HandleSIGINT, ["handleSIGTERM"] = options.HandleSIGTERM, ["handleSIGHUP"] = options.HandleSIGHUP, - ["timeout"] = TimeoutSettings.LaunchTimeout(options.Timeout), ["env"] = options.Env?.ToProtocol(), ["slowMo"] = options.SlowMo, ["ignoreHTTPSErrors"] = options.IgnoreHTTPSErrors, @@ -147,7 +146,7 @@ public async Task LaunchPersistentContextAsync(string userDataD channelArgs.Add("viewport", options.ViewportSize); } - JsonElement result = await SendMessageToServerAsync("launchPersistentContext", channelArgs).ConfigureAwait(false); + JsonElement result = await SendMessageToServerAsync("launchPersistentContext", channelArgs, timeout: TimeoutSettings.LaunchTimeout(options.Timeout)).ConfigureAwait(false); var browser = result.GetProperty("browser").ToObject(_connection.DefaultJsonSerializerOptions)!; browser.ConnectToBrowserType(this, options.TracesDir); var context = result.GetProperty("context").ToObject(_connection.DefaultJsonSerializerOptions)!; @@ -263,16 +262,18 @@ public async Task ConnectOverCDPAsync(string endpointURL, BrowserTypeC throw new ArgumentException("Connecting over CDP is only supported in Chromium."); } options ??= new BrowserTypeConnectOverCDPOptions(); - JsonElement result = await SendMessageToServerAsync("connectOverCDP", new Dictionary - { - { "endpointURL", endpointURL }, - { "headers", options.Headers?.ToProtocol() }, - { "slowMo", options.SlowMo }, - { "timeout", TimeoutSettings.LaunchTimeout(options.Timeout) }, - { "isLocal", options.IsLocal }, - { "noDefaults", options.NoDefaults }, - { "artifactsDir", options.ArtifactsDir }, - }).ConfigureAwait(false); + JsonElement result = await SendMessageToServerAsync( + "connectOverCDP", + new Dictionary + { + { "endpointURL", endpointURL }, + { "headers", options.Headers?.ToProtocol() }, + { "slowMo", options.SlowMo }, + { "isLocal", options.IsLocal }, + { "noDefaults", options.NoDefaults }, + { "artifactsDir", options.ArtifactsDir }, + }, + timeout: TimeoutSettings.LaunchTimeout(options.Timeout)).ConfigureAwait(false); Browser browser = result.GetProperty("browser").ToObject(_connection.DefaultJsonSerializerOptions); browser.ConnectToBrowserType(this, null); return browser; diff --git a/src/Playwright/Core/ElementHandle.cs b/src/Playwright/Core/ElementHandle.cs index d27d91270..ff37e1502 100644 --- a/src/Playwright/Core/ElementHandle.cs +++ b/src/Playwright/Core/ElementHandle.cs @@ -59,36 +59,42 @@ internal override void OnMessage(string method, JsonElement serverParams) new Dictionary { ["selector"] = selector, - ["timeout"] = _frame.Timeout(options?.Timeout), ["state"] = options?.State, ["strict"] = options?.Strict, - }).ConfigureAwait(false); + }, + timeout: _frame.Timeout(options?.Timeout)).ConfigureAwait(false); public Task WaitForElementStateAsync(ElementState state, ElementHandleWaitForElementStateOptions? options = default) - => SendMessageToServerAsync("waitForElementState", new Dictionary - { - ["state"] = state, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "waitForElementState", + new Dictionary + { + ["state"] = state, + }, + timeout: _frame.Timeout(options?.Timeout)); public Task PressAsync(string key, ElementHandlePressOptions? options = default) - => SendMessageToServerAsync("press", new Dictionary - { - ["key"] = key, - ["delay"] = options?.Delay, - ["timeout"] = _frame.Timeout(options?.Timeout), + => SendMessageToServerAsync( + "press", + new Dictionary + { + ["key"] = key, + ["delay"] = options?.Delay, #pragma warning disable CS0612 // Type or member is obsolete - ["noWaitAfter"] = options?.NoWaitAfter, + ["noWaitAfter"] = options?.NoWaitAfter, #pragma warning restore CS0612 // Type or member is obsolete - }); + }, + timeout: _frame.Timeout(options?.Timeout)); public Task TypeAsync(string text, ElementHandleTypeOptions? options = default) - => SendMessageToServerAsync("type", new Dictionary - { - ["text"] = text, - ["delay"] = options?.Delay, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "type", + new Dictionary + { + ["text"] = text, + ["delay"] = options?.Delay, + }, + timeout: _frame.Timeout(options?.Timeout)); public async Task ScreenshotAsync(ElementHandleScreenshotOptions? options = default) { @@ -103,7 +109,6 @@ public async Task ScreenshotAsync(ElementHandleScreenshotOptions? option ["type"] = options.Type, ["omitBackground"] = options.OmitBackground, ["path"] = options.Path, - ["timeout"] = _frame.Timeout(options.Timeout), ["animations"] = options.Animations, ["caret"] = options.Caret, ["scale"] = options.Scale, @@ -120,7 +125,7 @@ public async Task ScreenshotAsync(ElementHandleScreenshotOptions? option }).ToArray(); } - var result = (await SendMessageToServerAsync("screenshot", args).ConfigureAwait(false))!.Value.GetProperty("binary").GetBytesFromBase64(); + var result = (await SendMessageToServerAsync("screenshot", args, timeout: _frame.Timeout(options.Timeout)).ConfigureAwait(false))!.Value.GetProperty("binary").GetBytesFromBase64(); if (!string.IsNullOrEmpty(options.Path)) { @@ -132,30 +137,36 @@ public async Task ScreenshotAsync(ElementHandleScreenshotOptions? option } public Task FillAsync(string value, ElementHandleFillOptions? options = default) - => SendMessageToServerAsync("fill", new Dictionary - { - ["value"] = value, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["force"] = options?.Force, - }); + => SendMessageToServerAsync( + "fill", + new Dictionary + { + ["value"] = value, + ["force"] = options?.Force, + }, + timeout: _frame.Timeout(options?.Timeout)); public async Task ContentFrameAsync() => await SendMessageToServerAsync("contentFrame").ConfigureAwait(false); public Task HoverAsync(ElementHandleHoverOptions? options = default) - => SendMessageToServerAsync("hover", new Dictionary - { - ["force"] = options?.Force, - ["position"] = options?.Position, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["trial"] = options?.Trial, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - }); + => SendMessageToServerAsync( + "hover", + new Dictionary + { + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + }, + timeout: _frame.Timeout(options?.Timeout)); public Task ScrollIntoViewIfNeededAsync(ElementHandleScrollIntoViewIfNeededOptions? options = default) - => SendMessageToServerAsync("scrollIntoViewIfNeeded", new Dictionary - { - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "scrollIntoViewIfNeeded", + new Dictionary + { + }, + timeout: _frame.Timeout(options?.Timeout)); public async Task OwnerFrameAsync() => await SendMessageToServerAsync("ownerFrame").ConfigureAwait(false); @@ -170,34 +181,38 @@ public Task ScrollIntoViewIfNeededAsync(ElementHandleScrollIntoViewIfNeededOptio } public Task ClickAsync(ElementHandleClickOptions? options = default) - => SendMessageToServerAsync("click", new Dictionary - { - ["delay"] = options?.Delay, - ["button"] = options?.Button, - ["clickCount"] = options?.ClickCount, - ["force"] = options?.Force, + => SendMessageToServerAsync( + "click", + new Dictionary + { + ["delay"] = options?.Delay, + ["button"] = options?.Button, + ["clickCount"] = options?.ClickCount, + ["force"] = options?.Force, #pragma warning disable CS0612 // Type or member is obsolete - ["noWaitAfter"] = options?.NoWaitAfter, + ["noWaitAfter"] = options?.NoWaitAfter, #pragma warning restore CS0612 // Type or member is obsolete - ["steps"] = options?.Steps, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["trial"] = options?.Trial, - ["position"] = options?.Position, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - }); + ["steps"] = options?.Steps, + ["trial"] = options?.Trial, + ["position"] = options?.Position, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + }, + timeout: _frame.Timeout(options?.Timeout)); public Task DblClickAsync(ElementHandleDblClickOptions? options = default) - => SendMessageToServerAsync("dblclick", new Dictionary - { - ["delay"] = options?.Delay, - ["button"] = options?.Button, - ["force"] = options?.Force, - ["steps"] = options?.Steps, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["trial"] = options?.Trial, - ["position"] = options?.Position, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - }); + => SendMessageToServerAsync( + "dblclick", + new Dictionary + { + ["delay"] = options?.Delay, + ["button"] = options?.Button, + ["force"] = options?.Force, + ["steps"] = options?.Steps, + ["trial"] = options?.Trial, + ["position"] = options?.Position, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + }, + timeout: _frame.Timeout(options?.Timeout)); public Task SetInputFilesAsync(string files, ElementHandleSetInputFilesOptions? options = default) => SetInputFilesAsync(new[] { files }, options); @@ -210,15 +225,17 @@ public async Task SetInputFilesAsync(IEnumerable files, ElementHandleSet throw new PlaywrightException("Cannot set input files to detached element."); } var converted = await SetInputFilesHelpers.ConvertInputFilesAsync(files, (BrowserContext)frame.Page.Context).ConfigureAwait(false); - await SendMessageToServerAsync("setInputFiles", new Dictionary - { - ["payloads"] = converted.Payloads, - ["localPaths"] = converted.LocalPaths, - ["localDirectory"] = converted.LocalDirectory, - ["streams"] = converted.Streams, - ["directoryStream"] = converted.DirectoryStream, - ["timeout"] = _frame.Timeout(options?.Timeout), - }).ConfigureAwait(false); + await SendMessageToServerAsync( + "setInputFiles", + new Dictionary + { + ["payloads"] = converted.Payloads, + ["localPaths"] = converted.LocalPaths, + ["localDirectory"] = converted.LocalDirectory, + ["streams"] = converted.Streams, + ["directoryStream"] = converted.DirectoryStream, + }, + timeout: _frame.Timeout(options?.Timeout)).ConfigureAwait(false); } public Task SetInputFilesAsync(FilePayload files, ElementHandleSetInputFilesOptions? options = default) @@ -227,13 +244,15 @@ public Task SetInputFilesAsync(FilePayload files, ElementHandleSetInputFilesOpti public async Task SetInputFilesAsync(IEnumerable files, ElementHandleSetInputFilesOptions? options = default) { var converted = SetInputFilesHelpers.ConvertInputFiles(files); - await SendMessageToServerAsync("setInputFiles", new Dictionary - { - ["payloads"] = converted.Payloads, - ["localPaths"] = converted.LocalPaths, - ["streams"] = converted.Streams, - ["timeout"] = _frame.Timeout(options?.Timeout), - }).ConfigureAwait(false); + await SendMessageToServerAsync( + "setInputFiles", + new Dictionary + { + ["payloads"] = converted.Payloads, + ["localPaths"] = converted.LocalPaths, + ["streams"] = converted.Streams, + }, + timeout: _frame.Timeout(options?.Timeout)).ConfigureAwait(false); } public async Task QuerySelectorAsync(string selector) @@ -310,11 +329,13 @@ public Task DispatchEventAsync(string type, object? eventInit = null) public async Task TextContentAsync() => (await SendMessageToServerAsync("textContent").ConfigureAwait(false))?.GetProperty("value").ToString(); public Task SelectTextAsync(ElementHandleSelectTextOptions? options = default) - => SendMessageToServerAsync("selectText", new Dictionary - { - ["force"] = options?.Force, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "selectText", + new Dictionary + { + ["force"] = options?.Force, + }, + timeout: _frame.Timeout(options?.Timeout)); public Task> SelectOptionAsync(string value, ElementHandleSelectOptionOptions? options = default) #pragma warning disable CS0612 // Type or member is obsolete @@ -348,51 +369,61 @@ public Task> SelectOptionAsync(IEnumerable> _selectOptionAsync(IEnumerable values, bool? noWaitAfter, bool? force, float? timeout) { - return (await SendMessageToServerAsync("selectOption", new Dictionary - { - ["options"] = values, - ["force"] = force, - ["timeout"] = _frame.Timeout(timeout), - }).ConfigureAwait(false))!.Value.GetProperty("values").ToObject(); + return (await SendMessageToServerAsync( + "selectOption", + new Dictionary + { + ["options"] = values, + ["force"] = force, + }, + timeout: _frame.Timeout(timeout)).ConfigureAwait(false))!.Value.GetProperty("values").ToObject(); } private async Task> _selectOptionAsync(IEnumerable values, bool? noWaitAfter, bool? force, float? timeout) { - return (await SendMessageToServerAsync("selectOption", new Dictionary - { - ["elements"] = values, - ["force"] = force, - ["timeout"] = _frame.Timeout(timeout), - }).ConfigureAwait(false))!.Value.GetProperty("values").ToObject(); + return (await SendMessageToServerAsync( + "selectOption", + new Dictionary + { + ["elements"] = values, + ["force"] = force, + }, + timeout: _frame.Timeout(timeout)).ConfigureAwait(false))!.Value.GetProperty("values").ToObject(); } public Task CheckAsync(ElementHandleCheckOptions? options = default) - => SendMessageToServerAsync("check", new Dictionary - { - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "check", + new Dictionary + { + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + }, + timeout: _frame.Timeout(options?.Timeout)); public Task UncheckAsync(ElementHandleUncheckOptions? options = default) - => SendMessageToServerAsync("uncheck", new Dictionary - { - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "uncheck", + new Dictionary + { + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + }, + timeout: _frame.Timeout(options?.Timeout)); public Task TapAsync(ElementHandleTapOptions? options = default) - => SendMessageToServerAsync("tap", new Dictionary - { - ["force"] = options?.Force, - ["position"] = options?.Position, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - ["trial"] = options?.Trial, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "tap", + new Dictionary + { + ["force"] = options?.Force, + ["position"] = options?.Position, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + ["trial"] = options?.Trial, + }, + timeout: _frame.Timeout(options?.Timeout)); public async Task IsCheckedAsync() => (await SendMessageToServerAsync("isChecked").ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; @@ -410,13 +441,15 @@ public async Task InputValueAsync(ElementHandleInputValueOptions? option => (await SendMessageToServerAsync("inputValue").ConfigureAwait(false))!.Value.GetProperty("value").ToString(); public Task SetCheckedAsync(bool checkedState, ElementHandleSetCheckedOptions? options = null) - => SendMessageToServerAsync(checkedState ? "check" : "uncheck", new Dictionary - { - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + checkedState ? "check" : "uncheck", + new Dictionary + { + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + }, + timeout: _frame.Timeout(options?.Timeout)); internal static ScreenshotType DetermineScreenshotType(string path) { diff --git a/src/Playwright/Core/Frame.cs b/src/Playwright/Core/Frame.cs index f908065bb..4b48def53 100644 --- a/src/Playwright/Core/Frame.cs +++ b/src/Playwright/Core/Frame.cs @@ -187,14 +187,16 @@ public Task> SelectOptionAsync(string selector, IElementHa [MethodImpl(MethodImplOptions.NoInlining)] public async Task> SelectOptionAsync(string selector, IEnumerable values, FrameSelectOptionOptions? options = default) - => (await SendMessageToServerAsync("selectOption", new Dictionary - { - ["selector"] = selector, - ["elements"] = values.Select(x => x as ElementHandle), - ["strict"] = options?.Strict, - ["force"] = options?.Force, - ["timeout"] = Timeout(options?.Timeout), - }).ConfigureAwait(false))!.Value.GetProperty("values").ToObject().ToList().AsReadOnly(); + => (await SendMessageToServerAsync( + "selectOption", + new Dictionary + { + ["selector"] = selector, + ["elements"] = values.Select(x => x as ElementHandle), + ["strict"] = options?.Strict, + ["force"] = options?.Force, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))!.Value.GetProperty("values").ToObject().ToList().AsReadOnly(); [MethodImpl(MethodImplOptions.NoInlining)] public Task> SelectOptionAsync(string selector, SelectOptionValue values, FrameSelectOptionOptions? options = default) @@ -205,17 +207,19 @@ public Task> SelectOptionAsync(string selector, IEnumerabl => SelectOptionAsync(selector, values.Select(value => SelectOptionValueProtocol.From(value)), options); internal async Task> SelectOptionAsync(string selector, IEnumerable values, FrameSelectOptionOptions? options = default) - => (await SendMessageToServerAsync("selectOption", new Dictionary - { - ["selector"] = selector, - ["options"] = values, + => (await SendMessageToServerAsync( + "selectOption", + new Dictionary + { + ["selector"] = selector, + ["options"] = values, #pragma warning disable CS0612 // Type or member is obsolete - ["noWaitAfter"] = options?.NoWaitAfter, + ["noWaitAfter"] = options?.NoWaitAfter, #pragma warning restore CS0612 // Type or member is obsolete - ["strict"] = options?.Strict, - ["force"] = options?.Force, - ["timeout"] = Timeout(options?.Timeout), - }).ConfigureAwait(false))!.Value.GetProperty("values").ToObject().ToList().AsReadOnly(); + ["strict"] = options?.Strict, + ["force"] = options?.Force, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))!.Value.GetProperty("values").ToObject().ToList().AsReadOnly(); [MethodImpl(MethodImplOptions.NoInlining)] public async Task WaitForLoadStateAsync(LoadState? state = default, FrameWaitForLoadStateOptions? options = default) @@ -347,16 +351,18 @@ await waiter.WaitForEventAsync( [MethodImpl(MethodImplOptions.NoInlining)] public Task TapAsync(string selector, FrameTapOptions? options = default) - => SendMessageToServerAsync("tap", new Dictionary - { - ["selector"] = selector, - ["force"] = options?.Force, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["position"] = options?.Position, - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "tap", + new Dictionary + { + ["selector"] = selector, + ["force"] = options?.Force, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + ["trial"] = options?.Trial, + ["position"] = options?.Position, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); internal async Task QueryCountAsync(string selector) { @@ -373,34 +379,40 @@ public async Task ContentAsync() [MethodImpl(MethodImplOptions.NoInlining)] public Task FocusAsync(string selector, FrameFocusOptions? options = default) - => SendMessageToServerAsync("focus", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "focus", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task TypeAsync(string selector, string text, FrameTypeOptions? options = default) - => SendMessageToServerAsync("type", new Dictionary - { - ["selector"] = selector, - ["text"] = text, - ["delay"] = options?.Delay, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "type", + new Dictionary + { + ["selector"] = selector, + ["text"] = text, + ["delay"] = options?.Delay, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public async Task GetAttributeAsync(string selector, string name, FrameGetAttributeOptions? options = default) { - if ((await SendMessageToServerAsync("getAttribute", new Dictionary - { - ["selector"] = selector, - ["name"] = name, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.TryGetProperty("value", out JsonElement retValue) ?? false) + if ((await SendMessageToServerAsync( + "getAttribute", + new Dictionary + { + ["selector"] = selector, + ["name"] = name, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.TryGetProperty("value", out JsonElement retValue) ?? false) { return retValue.ToString(); } @@ -409,79 +421,93 @@ public Task TypeAsync(string selector, string text, FrameTypeOptions? options = [MethodImpl(MethodImplOptions.NoInlining)] public async Task InnerHTMLAsync(string selector, FrameInnerHTMLOptions? options = default) - => (await SendMessageToServerAsync("innerHTML", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); + => (await SendMessageToServerAsync( + "innerHTML", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); [MethodImpl(MethodImplOptions.NoInlining)] public async Task InnerTextAsync(string selector, FrameInnerTextOptions? options = default) - => (await SendMessageToServerAsync("innerText", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); + => (await SendMessageToServerAsync( + "innerText", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); [MethodImpl(MethodImplOptions.NoInlining)] public async Task TextContentAsync(string selector, FrameTextContentOptions? options = default) - => (await SendMessageToServerAsync("textContent", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.GetProperty("value").ToString(); + => (await SendMessageToServerAsync( + "textContent", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.GetProperty("value").ToString(); [MethodImpl(MethodImplOptions.NoInlining)] public Task HoverAsync(string selector, FrameHoverOptions? options = default) - => SendMessageToServerAsync("hover", new Dictionary - { - ["selector"] = selector, - ["force"] = options?.Force, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "hover", + new Dictionary + { + ["selector"] = selector, + ["force"] = options?.Force, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + ["position"] = options?.Position, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task PressAsync(string selector, string key, FramePressOptions? options = default) - => SendMessageToServerAsync("press", new Dictionary - { - ["selector"] = selector, - ["key"] = key, - ["delay"] = options?.Delay, - ["timeout"] = Timeout(options?.Timeout), + => SendMessageToServerAsync( + "press", + new Dictionary + { + ["selector"] = selector, + ["key"] = key, + ["delay"] = options?.Delay, #pragma warning disable CS0612 // Type or member is obsolete - ["noWaitAfter"] = options?.NoWaitAfter, + ["noWaitAfter"] = options?.NoWaitAfter, #pragma warning restore CS0612 // Type or member is obsolete - ["strict"] = options?.Strict, - }); + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task DispatchEventAsync(string selector, string type, object? eventInit = default, FrameDispatchEventOptions? options = default) - => SendMessageToServerAsync("dispatchEvent", new Dictionary - { - ["selector"] = selector, - ["type"] = type, - ["eventInit"] = ScriptsHelper.SerializedArgument(eventInit), - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "dispatchEvent", + new Dictionary + { + ["selector"] = selector, + ["type"] = type, + ["eventInit"] = ScriptsHelper.SerializedArgument(eventInit), + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task FillAsync(string selector, string value, FrameFillOptions? options = default) - => SendMessageToServerAsync("fill", new Dictionary - { - ["selector"] = selector, - ["value"] = value, - ["force"] = options?.Force, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "fill", + new Dictionary + { + ["selector"] = selector, + ["value"] = value, + ["force"] = options?.Force, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public async Task AddScriptTagAsync(FrameAddScriptTagOptions? options = default) @@ -547,17 +573,19 @@ public async Task SetInputFilesAsync(string selector, IEnumerable f private async Task _setInputFilesAsync(string selector, SetInputFilesFiles files, bool? noWaitAfter, float? timeout, bool? strict) { - await SendMessageToServerAsync("setInputFiles", new Dictionary - { - ["selector"] = selector, - ["payloads"] = files.Payloads, - ["localPaths"] = files.LocalPaths, - ["localDirectory"] = files.LocalDirectory, - ["streams"] = files.Streams, - ["directoryStream"] = files.DirectoryStream, - ["timeout"] = Timeout(timeout), - ["strict"] = strict, - }).ConfigureAwait(false); + await SendMessageToServerAsync( + "setInputFiles", + new Dictionary + { + ["selector"] = selector, + ["payloads"] = files.Payloads, + ["localPaths"] = files.LocalPaths, + ["localDirectory"] = files.LocalDirectory, + ["streams"] = files.Streams, + ["directoryStream"] = files.DirectoryStream, + ["strict"] = strict, + }, + timeout: Timeout(timeout)).ConfigureAwait(false); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -565,96 +593,110 @@ public Task ClickAsync(string selector, FrameClickOptions? options = default) => ClickInternalAsync(selector, options, null); internal Task ClickInternalAsync(string selector, FrameClickOptions? options, int? steps) - => SendMessageToServerAsync("click", new Dictionary - { - ["selector"] = selector, - ["button"] = options?.Button, - ["force"] = options?.Force, - ["delay"] = options?.Delay, - ["clickCount"] = options?.ClickCount, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - ["position"] = options?.Position, + => SendMessageToServerAsync( + "click", + new Dictionary + { + ["selector"] = selector, + ["button"] = options?.Button, + ["force"] = options?.Force, + ["delay"] = options?.Delay, + ["clickCount"] = options?.ClickCount, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + ["position"] = options?.Position, #pragma warning disable CS0612 // Type or member is obsolete - ["noWaitAfter"] = options?.NoWaitAfter, + ["noWaitAfter"] = options?.NoWaitAfter, #pragma warning restore CS0612 // Type or member is obsolete - ["steps"] = steps, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + ["steps"] = steps, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task DblClickAsync(string selector, FrameDblClickOptions? options = default) => DblClickInternalAsync(selector, options, null); internal Task DblClickInternalAsync(string selector, FrameDblClickOptions? options, int? steps) - => SendMessageToServerAsync("dblclick", new Dictionary - { - ["selector"] = selector, - ["button"] = options?.Button, - ["delay"] = options?.Delay, - ["force"] = options?.Force, - ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), - ["position"] = options?.Position, - ["steps"] = steps, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "dblclick", + new Dictionary + { + ["selector"] = selector, + ["button"] = options?.Button, + ["delay"] = options?.Delay, + ["force"] = options?.Force, + ["modifiers"] = options?.Modifiers?.Select(m => m.ToValueString()), + ["position"] = options?.Position, + ["steps"] = steps, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task CheckAsync(string selector, FrameCheckOptions? options = default) - => SendMessageToServerAsync("check", new Dictionary - { - ["selector"] = selector, - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "check", + new Dictionary + { + ["selector"] = selector, + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task UncheckAsync(string selector, FrameUncheckOptions? options = default) - => SendMessageToServerAsync("uncheck", new Dictionary - { - ["selector"] = selector, - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + "uncheck", + new Dictionary + { + ["selector"] = selector, + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task SetCheckedAsync(string selector, bool checkedState, FrameSetCheckedOptions? options = null) - => SendMessageToServerAsync(checkedState ? "check" : "uncheck", new Dictionary - { - ["selector"] = selector, - ["force"] = options?.Force, - ["position"] = options?.Position, - ["trial"] = options?.Trial, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }); + => SendMessageToServerAsync( + checkedState ? "check" : "uncheck", + new Dictionary + { + ["selector"] = selector, + ["force"] = options?.Force, + ["position"] = options?.Position, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public Task SetContentAsync(string html, FrameSetContentOptions? options = default) - => SendMessageToServerAsync("setContent", new Dictionary - { - ["html"] = html, - ["waitUntil"] = options?.WaitUntil, - ["timeout"] = Timeout(options?.Timeout), - }); + => SendMessageToServerAsync( + "setContent", + new Dictionary + { + ["html"] = html, + ["waitUntil"] = options?.WaitUntil, + }, + timeout: Timeout(options?.Timeout)); [MethodImpl(MethodImplOptions.NoInlining)] public async Task InputValueAsync(string selector, FrameInputValueOptions? options = null) - => (await SendMessageToServerAsync("inputValue", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); + => (await SendMessageToServerAsync( + "inputValue", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))!.Value.GetProperty("value").ToString(); [MethodImpl(MethodImplOptions.NoInlining)] public async Task QuerySelectorAsync(string selector) @@ -680,9 +722,9 @@ public async Task WaitForFunctionAsync(string expression, object? arg { ["expression"] = expression, ["arg"] = ScriptsHelper.SerializedArgument(arg), - ["timeout"] = Timeout(options?.Timeout), ["pollingInterval"] = options?.PollingInterval, - }).ConfigureAwait(false); + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task WaitForSelectorAsync(string selector, FrameWaitForSelectorOptions? options = default) @@ -691,11 +733,11 @@ public async Task WaitForFunctionAsync(string expression, object? arg new Dictionary { ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), ["state"] = options?.State, ["strict"] = options?.Strict, ["omitReturnValue"] = false, - }).ConfigureAwait(false); + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task EvaluateHandleAsync(string script, object? args = null) @@ -812,49 +854,59 @@ public ILocator Locator(string selector, FrameLocatorOptions? options = null) => [MethodImpl(MethodImplOptions.NoInlining)] public async Task GotoAsync(string url, FrameGotoOptions? options = default) - => await SendMessageToServerAsync("goto", new Dictionary - { - ["url"] = url, - ["timeout"] = NavigationTimeout(options?.Timeout), - ["waitUntil"] = options?.WaitUntil, - ["referer"] = options?.Referer, - }).ConfigureAwait(false); + => await SendMessageToServerAsync( + "goto", + new Dictionary + { + ["url"] = url, + ["waitUntil"] = options?.WaitUntil, + ["referer"] = options?.Referer, + }, + timeout: NavigationTimeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task IsCheckedAsync(string selector, FrameIsCheckedOptions? options = default) - => (await SendMessageToServerAsync("isChecked", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; + => (await SendMessageToServerAsync( + "isChecked", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; [MethodImpl(MethodImplOptions.NoInlining)] public async Task IsDisabledAsync(string selector, FrameIsDisabledOptions? options = default) - => (await SendMessageToServerAsync("isDisabled", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; + => (await SendMessageToServerAsync( + "isDisabled", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; [MethodImpl(MethodImplOptions.NoInlining)] public async Task IsEditableAsync(string selector, FrameIsEditableOptions? options = default) - => (await SendMessageToServerAsync("isEditable", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; + => (await SendMessageToServerAsync( + "isEditable", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; [MethodImpl(MethodImplOptions.NoInlining)] public async Task IsEnabledAsync(string selector, FrameIsEnabledOptions? options = default) - => (await SendMessageToServerAsync("isEnabled", new Dictionary - { - ["selector"] = selector, - ["timeout"] = Timeout(options?.Timeout), - ["strict"] = options?.Strict, - }).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; + => (await SendMessageToServerAsync( + "isEnabled", + new Dictionary + { + ["selector"] = selector, + ["strict"] = options?.Strict, + }, + timeout: Timeout(options?.Timeout)).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default; [MethodImpl(MethodImplOptions.NoInlining)] public async Task IsHiddenAsync(string selector, FrameIsHiddenOptions? options = default) @@ -886,18 +938,20 @@ public Task WaitForURLAsync(Func url, FrameWaitForURLOptions? opti [MethodImpl(MethodImplOptions.NoInlining)] public Task DragAndDropAsync(string source, string target, FrameDragAndDropOptions? options = null) - => SendMessageToServerAsync("dragAndDrop", new Dictionary - { - ["source"] = source, - ["target"] = target, - ["force"] = options?.Force, - ["steps"] = options?.Steps, - ["timeout"] = Timeout(options?.Timeout), - ["trial"] = options?.Trial, - ["strict"] = options?.Strict, - ["sourcePosition"] = options?.SourcePosition, - ["targetPosition"] = options?.TargetPosition, - }); + => SendMessageToServerAsync( + "dragAndDrop", + new Dictionary + { + ["source"] = source, + ["target"] = target, + ["force"] = options?.Force, + ["steps"] = options?.Steps, + ["trial"] = options?.Trial, + ["strict"] = options?.Strict, + ["sourcePosition"] = options?.SourcePosition, + ["targetPosition"] = options?.TargetPosition, + }, + timeout: Timeout(options?.Timeout)); internal async Task DropAsync(string selector, DropPayload payload, Position? position, float? timeout, bool strict) { @@ -917,35 +971,39 @@ internal async Task DropAsync(string selector, DropPayload payload, Position? po ["value"] = kv.Value, }).ToArray(); - await SendMessageToServerAsync("drop", new Dictionary - { - ["selector"] = selector, - ["strict"] = strict, - ["position"] = position, - ["payloads"] = fileParams?.Payloads, - ["localPaths"] = fileParams?.LocalPaths, - ["streams"] = fileParams?.Streams, - ["data"] = data, - ["timeout"] = Timeout(timeout), - }).ConfigureAwait(false); + await SendMessageToServerAsync( + "drop", + new Dictionary + { + ["selector"] = selector, + ["strict"] = strict, + ["position"] = position, + ["payloads"] = fileParams?.Payloads, + ["localPaths"] = fileParams?.LocalPaths, + ["streams"] = fileParams?.Streams, + ["data"] = data, + }, + timeout: Timeout(timeout)).ConfigureAwait(false); } internal async Task ExpectAsync(string? selector, string expression, FrameExpectOptions options) { try { - await SendMessageToServerAsync("expect", new Dictionary - { - ["selector"] = selector, - ["expression"] = expression, - ["expressionArg"] = options.ExpressionArg, - ["expectedText"] = options.ExpectedText, - ["expectedNumber"] = options.ExpectedNumber, - ["expectedValue"] = options.ExpectedValue, - ["useInnerText"] = options.UseInnerText, - ["isNot"] = options.IsNot, - ["timeout"] = options.Timeout, - }).ConfigureAwait(false); + await SendMessageToServerAsync( + "expect", + new Dictionary + { + ["selector"] = selector, + ["expression"] = expression, + ["expressionArg"] = options.ExpressionArg, + ["expectedText"] = options.ExpectedText, + ["expectedNumber"] = options.ExpectedNumber, + ["expectedValue"] = options.ExpectedValue, + ["useInnerText"] = options.UseInnerText, + ["isNot"] = options.IsNot, + }, + timeout: options.Timeout).ConfigureAwait(false); return new FrameExpectResult { Matches = !options.IsNot }; } catch (Exception e) when (e.Data.Contains(Connection.ErrorDetailsDataKey)) diff --git a/src/Playwright/Core/LocalUtils.cs b/src/Playwright/Core/LocalUtils.cs index e97853188..40ec64aa2 100644 --- a/src/Playwright/Core/LocalUtils.cs +++ b/src/Playwright/Core/LocalUtils.cs @@ -93,14 +93,16 @@ internal Task HarUnzipAsync(string zipFile, string harFile, string? resourcesDir }); internal async Task ConnectAsync(string wsEndpoint, IEnumerable>? headers = default, float? slowMo = default, float? timeout = default, string? exposeNetwork = default) - => (await SendMessageToServerAsync("connect", new Dictionary - { - { "endpoint", wsEndpoint }, - { "headers", headers }, - { "slowMo", slowMo }, - { "timeout", timeout ?? 0 }, - { "exposeNetwork", exposeNetwork }, - }).ConfigureAwait(false))!.Value.GetObject("pipe", _connection); + => (await SendMessageToServerAsync( + "connect", + new Dictionary + { + { "endpoint", wsEndpoint }, + { "headers", headers }, + { "slowMo", slowMo }, + { "exposeNetwork", exposeNetwork }, + }, + timeout: timeout ?? 0).ConfigureAwait(false))!.Value.GetObject("pipe", _connection); internal void AddStackToTracingNoReply(List stack, int id) => SendMessageToServerAsync("addStackToTracingNoReply", new Dictionary diff --git a/src/Playwright/Core/Locator.cs b/src/Playwright/Core/Locator.cs index 41174c2fa..10be5e4f8 100644 --- a/src/Playwright/Core/Locator.cs +++ b/src/Playwright/Core/Locator.cs @@ -278,9 +278,9 @@ public Task BlurAsync(LocatorBlurOptions? options = null) new Dictionary { ["selector"] = _selector, - ["timeout"] = _frame.Timeout(options?.Timeout), ["strict"] = true, - }); + }, + timeout: _frame.Timeout(options?.Timeout)); public Task CountAsync() => _frame.QueryCountAsync(_selector); @@ -388,26 +388,30 @@ public async Task> AllTextContentsAsync() public Task WaitForAsync(LocatorWaitForOptions? options = null) { - return _frame.SendMessageToServerAsync("waitForSelector", new Dictionary - { - ["selector"] = _selector, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["state"] = options?.State, - ["strict"] = true, - ["omitReturnValue"] = true, - }); + return _frame.SendMessageToServerAsync( + "waitForSelector", + new Dictionary + { + ["selector"] = _selector, + ["state"] = options?.State, + ["strict"] = true, + ["omitReturnValue"] = true, + }, + timeout: _frame.Timeout(options?.Timeout)); } public Task WaitForFunctionAsync(string expression, object? arg = default, LocatorWaitForFunctionOptions? options = default) { - return _frame.SendMessageToServerAsync("waitForFunction", new Dictionary - { - ["selector"] = _selector, - ["strict"] = true, - ["expression"] = expression, - ["arg"] = ScriptsHelper.SerializedArgument(arg), - ["timeout"] = _frame.Timeout(options?.Timeout), - }); + return _frame.SendMessageToServerAsync( + "waitForFunction", + new Dictionary + { + ["selector"] = _selector, + ["strict"] = true, + ["expression"] = expression, + ["arg"] = ScriptsHelper.SerializedArgument(arg), + }, + timeout: _frame.Timeout(options?.Timeout)); } internal Task ExpectAsync(string expression, FrameExpectOptions options, string? title) @@ -448,13 +452,15 @@ private Task WithElementAsync(Func { - var handle = await _frame.SendMessageToServerAsync("waitForSelector", new Dictionary - { - ["selector"] = this._selector, - ["state"] = WaitForSelectorState.Attached, - ["timeout"] = timeout, - ["strict"] = true, - }).ConfigureAwait(false); + var handle = await _frame.SendMessageToServerAsync( + "waitForSelector", + new Dictionary + { + ["selector"] = this._selector, + ["state"] = WaitForSelectorState.Attached, + ["strict"] = true, + }, + timeout: timeout).ConfigureAwait(false); if (handle == null) { throw new PlaywrightException($"Could not resolve {this._selector} to DOM Element"); @@ -661,13 +667,15 @@ async Task> ILocator.AllAsync() public async Task AriaSnapshotAsync(LocatorAriaSnapshotOptions? options = null) { - var result = await _frame.SendMessageToServerAsync("ariaSnapshot", new Dictionary - { - ["selector"] = _selector, - ["timeout"] = _frame.Timeout(options?.Timeout), - ["mode"] = options?.Mode, - ["depth"] = options?.Depth, - }).ConfigureAwait(false); + var result = await _frame.SendMessageToServerAsync( + "ariaSnapshot", + new Dictionary + { + ["selector"] = _selector, + ["mode"] = options?.Mode, + ["depth"] = options?.Depth, + }, + timeout: _frame.Timeout(options?.Timeout)).ConfigureAwait(false); return result!.Value.GetProperty("snapshot").ToString(); } diff --git a/src/Playwright/Core/Page.cs b/src/Playwright/Core/Page.cs index 64de28d36..a395384f0 100644 --- a/src/Playwright/Core/Page.cs +++ b/src/Playwright/Core/Page.cs @@ -707,26 +707,28 @@ public async Task ScreenshotAsync(PageScreenshotOptions? options = defau options.Type = ElementHandle.DetermineScreenshotType(options.Path); } - var result = (await SendMessageToServerAsync("screenshot", new Dictionary - { - ["fullPage"] = options.FullPage, - ["omitBackground"] = options.OmitBackground, - ["clip"] = options.Clip, - ["path"] = options.Path, - ["type"] = options.Type, - ["timeout"] = _timeoutSettings.Timeout(options.Timeout), - ["animations"] = options.Animations, - ["caret"] = options.Caret, - ["scale"] = options.Scale, - ["quality"] = options.Quality, - ["maskColor"] = options.MaskColor, - ["style"] = options.Style, - ["mask"] = options.Mask?.Select(locator => new Dictionary + var result = (await SendMessageToServerAsync( + "screenshot", + new Dictionary { - ["frame"] = ((Locator)locator)._frame, - ["selector"] = ((Locator)locator)._selector, - }).ToArray(), - }).ConfigureAwait(false))!.Value.GetProperty("binary").GetBytesFromBase64(); + ["fullPage"] = options.FullPage, + ["omitBackground"] = options.OmitBackground, + ["clip"] = options.Clip, + ["path"] = options.Path, + ["type"] = options.Type, + ["animations"] = options.Animations, + ["caret"] = options.Caret, + ["scale"] = options.Scale, + ["quality"] = options.Quality, + ["maskColor"] = options.MaskColor, + ["style"] = options.Style, + ["mask"] = options.Mask?.Select(locator => new Dictionary + { + ["frame"] = ((Locator)locator)._frame, + ["selector"] = ((Locator)locator)._selector, + }).ToArray(), + }, + timeout: _timeoutSettings.Timeout(options.Timeout)).ConfigureAwait(false))!.Value.GetProperty("binary").GetBytesFromBase64(); if (!string.IsNullOrEmpty(options.Path)) { @@ -818,27 +820,33 @@ public Task DblClickAsync(string selector, PageDblClickOptions? options = defaul [MethodImpl(MethodImplOptions.NoInlining)] public async Task GoBackAsync(PageGoBackOptions? options = default) - => await SendMessageToServerAsync("goBack", new Dictionary - { - ["timeout"] = _timeoutSettings.NavigationTimeout(options?.Timeout), - ["waitUntil"] = options?.WaitUntil, - }).ConfigureAwait(false); + => await SendMessageToServerAsync( + "goBack", + new Dictionary + { + ["waitUntil"] = options?.WaitUntil, + }, + timeout: _timeoutSettings.NavigationTimeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task GoForwardAsync(PageGoForwardOptions? options = default) - => await SendMessageToServerAsync("goForward", new Dictionary - { - ["timeout"] = _timeoutSettings.NavigationTimeout(options?.Timeout), - ["waitUntil"] = options?.WaitUntil, - }).ConfigureAwait(false); + => await SendMessageToServerAsync( + "goForward", + new Dictionary + { + ["waitUntil"] = options?.WaitUntil, + }, + timeout: _timeoutSettings.NavigationTimeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task ReloadAsync(PageReloadOptions? options = default) - => await SendMessageToServerAsync("reload", new Dictionary - { - ["timeout"] = _timeoutSettings.NavigationTimeout(options?.Timeout), - ["waitUntil"] = options?.WaitUntil, - }).ConfigureAwait(false); + => await SendMessageToServerAsync( + "reload", + new Dictionary + { + ["waitUntil"] = options?.WaitUntil, + }, + timeout: _timeoutSettings.NavigationTimeout(options?.Timeout)).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public Task HideHighlightAsync() => SendMessageToServerAsync("hideHighlight"); @@ -1558,12 +1566,14 @@ public async Task> RequestsAsync() [MethodImpl(MethodImplOptions.NoInlining)] public async Task AriaSnapshotAsync(PageAriaSnapshotOptions? options = default) { - var result = await MainFrame.SendMessageToServerAsync("ariaSnapshot", new Dictionary - { - ["timeout"] = MainFrame.Timeout(options?.Timeout), - ["mode"] = options?.Mode, - ["depth"] = options?.Depth, - }).ConfigureAwait(false); + var result = await MainFrame.SendMessageToServerAsync( + "ariaSnapshot", + new Dictionary + { + ["mode"] = options?.Mode, + ["depth"] = options?.Depth, + }, + timeout: MainFrame.Timeout(options?.Timeout)).ConfigureAwait(false); return result!.Value.GetProperty("snapshot").ToString(); } diff --git a/src/Playwright/Transport/ChannelOwner.cs b/src/Playwright/Transport/ChannelOwner.cs index cf9fe7f18..b815b2d8b 100644 --- a/src/Playwright/Transport/ChannelOwner.cs +++ b/src/Playwright/Transport/ChannelOwner.cs @@ -127,11 +127,13 @@ private void UpdateEventSubscription(string eventName, bool enabled) internal Task SendMessageToServerAsync( string method, Dictionary? args = null, - bool keepNulls = false) - => SendMessageToServerAsync(method, args, keepNulls); + bool keepNulls = false, + float? timeout = null) + => SendMessageToServerAsync(method, args, keepNulls, timeout); internal Task SendMessageToServerAsync( string method, Dictionary? args = null, - bool keepNulls = false) => _connection.SendMessageToServerAsync(this, method, args, keepNulls); + bool keepNulls = false, + float? timeout = null) => _connection.SendMessageToServerAsync(this, method, args, keepNulls, timeout); } diff --git a/src/Playwright/Transport/Connection.cs b/src/Playwright/Transport/Connection.cs index 9707c0b9e..3471ba9e4 100644 --- a/src/Playwright/Transport/Connection.cs +++ b/src/Playwright/Transport/Connection.cs @@ -128,20 +128,23 @@ internal void SetIsTracing(bool isTracing) ChannelOwner? @object, string method, Dictionary? args = null, - bool keepNulls = false) - => SendMessageToServerAsync(@object, method, args, keepNulls); + bool keepNulls = false, + float? timeout = null) + => SendMessageToServerAsync(@object, method, args, keepNulls, timeout); internal Task SendMessageToServerAsync( ChannelOwner? @object, string method, Dictionary? args = null, - bool keepNulls = false) => WrapApiCallAsync(() => InnerSendMessageToServerAsync(@object, method, args, keepNulls), false, null); + bool keepNulls = false, + float? timeout = null) => WrapApiCallAsync(() => InnerSendMessageToServerAsync(@object, method, args, keepNulls, timeout), false, null); private async Task InnerSendMessageToServerAsync( ChannelOwner? @object, string method, Dictionary? dictionary = null, - bool keepNulls = false) + bool keepNulls = false, + float? timeout = null) { // Fire-and-forget: server intentionally never replies to __waitInfo__, // so silently drop it after the connection is closed or the object was collected. @@ -181,10 +184,9 @@ private async Task InnerSendMessageToServerAsync( ["internal"] = isInternal, ["wallTime"] = DateTimeOffset.Now.ToUnixTimeMilliseconds(), }; - if (sanitizedArgs.TryGetValue("timeout", out var timeout)) + if (timeout.HasValue) { - sanitizedArgs.Remove("timeout"); - metadata["timeout"] = timeout; + metadata["timeout"] = timeout.Value; } if (!string.IsNullOrEmpty(title)) {