Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Playwright/API/Generated/IWebSocketRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public partial interface IWebSocketRoute
/// code</a> and an optional <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#reason">close
/// reason</a>.
/// </param>
void OnClose(Action<int?, string> handler);
void OnClose(Action<int?, string?> handler);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/// <summary>
/// <para>
Expand Down
1 change: 1 addition & 0 deletions src/Playwright/Core/BrowserContextEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

namespace Microsoft.Playwright.Core;

Expand Down
19 changes: 10 additions & 9 deletions src/Playwright/Core/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System;
using System.Collections.Generic;
Expand All @@ -30,13 +31,13 @@ namespace Microsoft.Playwright.Core;

internal class Clock(BrowserContext browserContext) : IClock
{
public async Task InstallAsync(ClockInstallOptions options = null)
public async Task InstallAsync(ClockInstallOptions? options = null)
{
options ??= new();
Dictionary<string, object> args = null;
if ((options.Time ?? options.TimeString) != null)
Dictionary<string, object?> args = null!;
if ((options.TimeString ?? options.Time) != null)
{
args = ParseTime(options.Time ?? options.TimeString);
args = ParseTime(options.TimeString ?? options.Time);
}
else if (options.TimeDate != null)
{
Expand All @@ -45,16 +46,16 @@ public async Task InstallAsync(ClockInstallOptions options = null)
await browserContext.SendMessageToServerAsync("clockInstall", args).ConfigureAwait(false);
}

private static Dictionary<string, object> ParseTime(string timeString)
private static Dictionary<string, object?> ParseTime(string? timeString)
=> new() { ["timeString"] = timeString };

private static Dictionary<string, object> ParseTime(DateTime? timeDate)
=> new() { ["timeNumber"] = ((DateTimeOffset)timeDate.Value).ToUnixTimeMilliseconds() };
private static Dictionary<string, object?> ParseTime(DateTime? timeDate)
=> new() { ["timeNumber"] = ((DateTimeOffset?)timeDate)?.ToUnixTimeMilliseconds() };

private Dictionary<string, object> ParseTicks(long ticks)
private Dictionary<string, object?> ParseTicks(long ticks)
=> new() { ["ticksNumber"] = ticks };

private Dictionary<string, object> ParseTicks(string ticks)
private Dictionary<string, object?> ParseTicks(string ticks)
=> new() { ["ticksString"] = ticks };

public Task FastForwardAsync(long ticks)
Expand Down
11 changes: 6 additions & 5 deletions src/Playwright/Core/ConsoleMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -55,17 +56,17 @@ internal ConsoleMessage(BrowserContextConsoleEvent @event)
internal class BrowserContextConsoleEvent
{
[JsonPropertyName("page")]
public Page Page { get; set; }
public Page Page { get; set; } = null!;

[JsonPropertyName("type")]
public string Type { get; set; }
public string Type { get; set; } = null!;

[JsonPropertyName("text")]
public string Text { get; set; }
public string Text { get; set; } = null!;

[JsonPropertyName("args")]
public List<JSHandle> Args { get; set; }
public List<JSHandle> Args { get; set; } = null!;

[JsonPropertyName("location")]
public ConsoleMessageLocation Location { get; set; }
public ConsoleMessageLocation Location { get; set; } = null!;
}
3 changes: 2 additions & 1 deletion src/Playwright/Core/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System.Threading.Tasks;

Expand Down Expand Up @@ -51,7 +52,7 @@ internal Download(IPage page, string url, string suggestedFilename, Artifact art

public Task<string> PathAsync() => _artifact.PathAfterFinishedAsync();

public Task<string> FailureAsync() => _artifact.FailureAsync();
public Task<string?> FailureAsync() => _artifact.FailureAsync();

public Task DeleteAsync() => _artifact.DeleteAsync();

Expand Down
11 changes: 6 additions & 5 deletions src/Playwright/Core/FileChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -53,19 +54,19 @@ public FileChooser(IPage page, ElementHandle element, bool multiple)

public bool IsMultiple { get; set; }

public Task SetFilesAsync(string files, FileChooserSetFilesOptions options = default)
public Task SetFilesAsync(string files, FileChooserSetFilesOptions? options = default)
=> ElementImpl.SetInputFilesAsync(files, Map(options));

public Task SetFilesAsync(IEnumerable<string> files, FileChooserSetFilesOptions options = default)
public Task SetFilesAsync(IEnumerable<string> files, FileChooserSetFilesOptions? options = default)
=> ElementImpl.SetInputFilesAsync(files, Map(options));

public Task SetFilesAsync(FilePayload files, FileChooserSetFilesOptions options = default)
public Task SetFilesAsync(FilePayload files, FileChooserSetFilesOptions? options = default)
=> ElementImpl.SetInputFilesAsync(files, Map(options));

public Task SetFilesAsync(IEnumerable<FilePayload> files, FileChooserSetFilesOptions options = default)
public Task SetFilesAsync(IEnumerable<FilePayload> files, FileChooserSetFilesOptions? options = default)
=> ElementImpl.SetInputFilesAsync(files, Map(options));

private ElementHandleSetInputFilesOptions Map(FileChooserSetFilesOptions options)
private ElementHandleSetInputFilesOptions? Map(FileChooserSetFilesOptions? options)
{
if (options == null)
{
Expand Down
1 change: 1 addition & 0 deletions src/Playwright/Core/FormData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System;
using System.Collections.Generic;
Expand Down
27 changes: 14 additions & 13 deletions src/Playwright/Core/FrameLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System.Text.RegularExpressions;

Expand All @@ -45,25 +46,25 @@ public FrameLocator(Frame parent, string selector)

public ILocator Owner => new Locator(_frame, _frameSelector);

ILocator IFrameLocator.GetByAltText(string text, FrameLocatorGetByAltTextOptions options)
ILocator IFrameLocator.GetByAltText(string text, FrameLocatorGetByAltTextOptions? options)
=> Locator(Core.Locator.GetByAltTextSelector(text, options?.Exact));

public ILocator GetByAltText(Regex text, FrameLocatorGetByAltTextOptions options = null)
public ILocator GetByAltText(Regex? text, FrameLocatorGetByAltTextOptions? options = null)
=> Locator(Core.Locator.GetByAltTextSelector(text, options?.Exact));

public ILocator GetByLabel(string text, FrameLocatorGetByLabelOptions options = null)
public ILocator GetByLabel(string text, FrameLocatorGetByLabelOptions? options = null)
=> Locator(Core.Locator.GetByLabelSelector(text, options?.Exact));

public ILocator GetByLabel(Regex text, FrameLocatorGetByLabelOptions options = null)
public ILocator GetByLabel(Regex text, FrameLocatorGetByLabelOptions? options = null)
=> Locator(Core.Locator.GetByLabelSelector(text, options?.Exact));

public ILocator GetByPlaceholder(string text, FrameLocatorGetByPlaceholderOptions options = null)
public ILocator GetByPlaceholder(string text, FrameLocatorGetByPlaceholderOptions? options = null)
=> Locator(Core.Locator.GetByPlaceholderSelector(text, options?.Exact));

public ILocator GetByPlaceholder(Regex text, FrameLocatorGetByPlaceholderOptions options = null)
public ILocator GetByPlaceholder(Regex text, FrameLocatorGetByPlaceholderOptions? options = null)
=> Locator(Core.Locator.GetByPlaceholderSelector(text, options?.Exact));

public ILocator GetByRole(AriaRole role, FrameLocatorGetByRoleOptions options = null)
public ILocator GetByRole(AriaRole role, FrameLocatorGetByRoleOptions? options = null)
=> Locator(Core.Locator.GetByRoleSelector(role, new(options)));

public ILocator GetByTestId(string testId)
Expand All @@ -72,21 +73,21 @@ public ILocator GetByTestId(string testId)
public ILocator GetByTestId(Regex testId)
=> Locator(Core.Locator.GetByTestIdSelector(Core.Locator.TestIdAttributeName(), testId));

public ILocator GetByText(string text, FrameLocatorGetByTextOptions options = null)
public ILocator GetByText(string text, FrameLocatorGetByTextOptions? options = null)
=> Locator(Core.Locator.GetByTextSelector(text, options?.Exact));

public ILocator GetByText(Regex text, FrameLocatorGetByTextOptions options = null)
public ILocator GetByText(Regex text, FrameLocatorGetByTextOptions? options = null)
=> Locator(Core.Locator.GetByTextSelector(text, options?.Exact));

public ILocator GetByTitle(string text, FrameLocatorGetByTitleOptions options = null)
public ILocator GetByTitle(string text, FrameLocatorGetByTitleOptions? options = null)
=> Locator(Core.Locator.GetByTitleSelector(text, options?.Exact));

public ILocator GetByTitle(Regex text, FrameLocatorGetByTitleOptions options = null)
public ILocator GetByTitle(Regex text, FrameLocatorGetByTitleOptions? options = null)
=> Locator(Core.Locator.GetByTitleSelector(text, options?.Exact));

IFrameLocator IFrameLocator.FrameLocator(string selector) => new FrameLocator(_frame, $"{_frameSelector} >> internal:control=enter-frame >> {selector}");

public ILocator Locator(string selector, FrameLocatorLocatorOptions options = null)
public ILocator Locator(string selector, FrameLocatorLocatorOptions? options = null)
=> new Locator(_frame, $"{_frameSelector} >> internal:control=enter-frame >> {selector}", new()
{
Has = options?.Has,
Expand All @@ -99,7 +100,7 @@ public ILocator Locator(string selector, FrameLocatorLocatorOptions options = nu
HasNotTextString = options?.HasNotTextString,
});

public ILocator Locator(ILocator locator, FrameLocatorLocatorOptions options = null)
public ILocator Locator(ILocator locator, FrameLocatorLocatorOptions? options = null)
{
var locatorImpl = (Locator)locator;
if (locatorImpl._frame != _frame)
Expand Down
23 changes: 12 additions & 11 deletions src/Playwright/Core/JSHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System;
using System.Collections.Generic;
Expand All @@ -43,33 +44,33 @@ internal JSHandle(ChannelOwner parent, string guid, JSHandleInitializer initiali
protected string Preview { get; set; }

[MethodImpl(MethodImplOptions.NoInlining)]
public IElementHandle AsElement() => this as IElementHandle;
public IElementHandle AsElement() => (IElementHandle)this;

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task<JsonElement?> EvaluateAsync(string expression, object arg = null)
public async Task<JsonElement?> EvaluateAsync(string expression, object? arg = null)
=> ScriptsHelper.ParseEvaluateResult<JsonElement?>(await SendMessageToServerAsync<JsonElement?>(
"evaluateExpression",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["expression"] = expression,
["arg"] = ScriptsHelper.SerializedArgument(arg),
}).ConfigureAwait(false));

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task<IJSHandle> EvaluateHandleAsync(string expression, object arg = null)
public async Task<IJSHandle> EvaluateHandleAsync(string expression, object? arg = null)
=> await SendMessageToServerAsync<JSHandle>(
"evaluateExpressionHandle",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["expression"] = expression,
["arg"] = ScriptsHelper.SerializedArgument(arg),
}).ConfigureAwait(false);

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task<T> EvaluateAsync<T>(string expression, object arg = null)
public async Task<T> EvaluateAsync<T>(string expression, object? arg = null)
=> ScriptsHelper.ParseEvaluateResult<T>(await SendMessageToServerAsync<JsonElement?>(
"evaluateExpression",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["expression"] = expression,
["arg"] = ScriptsHelper.SerializedArgument(arg),
Expand All @@ -81,7 +82,7 @@ public async Task<T> EvaluateAsync<T>(string expression, object arg = null)
[MethodImpl(MethodImplOptions.NoInlining)]
public async Task<IJSHandle> GetPropertyAsync(string propertyName) => await SendMessageToServerAsync<JSHandle>(
"getProperty",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["name"] = propertyName,
}).ConfigureAwait(false);
Expand All @@ -90,7 +91,7 @@ public async Task<IJSHandle> GetPropertyAsync(string propertyName) => await Send
public async Task<Dictionary<string, IJSHandle>> GetPropertiesAsync()
{
var result = new Dictionary<string, IJSHandle>();
var channelResult = (await SendMessageToServerAsync("getPropertyList").ConfigureAwait(false))?
var channelResult = (await SendMessageToServerAsync("getPropertyList").ConfigureAwait(false)).Value
.GetProperty("properties").ToObject<List<JSElementProperty>>(_connection.DefaultJsonSerializerOptions);

foreach (var kv in channelResult)
Expand Down Expand Up @@ -119,7 +120,7 @@ public async ValueTask DisposeAsync()

internal class JSElementProperty
{
public string Name { get; set; }
public string Name { get; set; } = null!;

public JSHandle Value { get; set; }
public JSHandle Value { get; set; } = null!;
}
7 changes: 4 additions & 3 deletions src/Playwright/Core/JsonPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
Expand All @@ -42,9 +43,9 @@ public JsonPipe(ChannelOwner parent, string guid, JsonPipeInitializer initialize
_initializer = initializer;
}

public event EventHandler<PlaywrightServerMessage> Message;
public event EventHandler<PlaywrightServerMessage>? Message;

public event EventHandler<string> Closed;
public event EventHandler<string?>? Closed;

internal override void OnMessage(string method, JsonElement serverParams)
{
Expand All @@ -64,7 +65,7 @@ internal override void OnMessage(string method, JsonElement serverParams)
public Task CloseAsync() => SendMessageToServerAsync("close");

[MethodImpl(MethodImplOptions.NoInlining)]
public Task SendAsync(object message) => SendMessageToServerAsync("send", new Dictionary<string, object>
public Task SendAsync(object message) => SendMessageToServerAsync("send", new Dictionary<string, object?>
{
{ "message", message },
});
Expand Down
15 changes: 8 additions & 7 deletions src/Playwright/Core/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#nullable enable

using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -39,32 +40,32 @@ public Keyboard(Page page)
public Task DownAsync(string key)
=> _page.SendMessageToServerAsync(
"keyboardDown",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["key"] = key,
});

public Task UpAsync(string key)
=> _page.SendMessageToServerAsync(
"keyboardUp",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["key"] = key,
});

public Task PressAsync(string key, KeyboardPressOptions options = default)
public Task PressAsync(string key, KeyboardPressOptions? options = default)
=> _page.SendMessageToServerAsync(
"keyboardPress",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["key"] = key,
["delay"] = options?.Delay,
});

public Task TypeAsync(string text, KeyboardTypeOptions options = default)
public Task TypeAsync(string text, KeyboardTypeOptions? options = default)
=> _page.SendMessageToServerAsync(
"keyboardType",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["text"] = text,
["delay"] = options?.Delay,
Expand All @@ -73,7 +74,7 @@ public Task TypeAsync(string text, KeyboardTypeOptions options = default)
public Task InsertTextAsync(string text)
=> _page.SendMessageToServerAsync(
"keyboardInsertText",
new Dictionary<string, object>
new Dictionary<string, object?>
{
["text"] = text,
});
Expand Down
Loading