diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs index 4bb970bf50ea8..8fd178f1655d5 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using System; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.BrowsingContext; @@ -56,9 +57,9 @@ public sealed record BoxClipRectangle(double X, double Y, double Width, double H public sealed record ElementClipRectangle(Script.ISharedReference Element) : ClipRectangle; -public sealed record CaptureScreenshotResult(string Data) : EmptyResult +public sealed record CaptureScreenshotResult(ReadOnlyMemory Data) : EmptyResult { public static implicit operator byte[](CaptureScreenshotResult captureScreenshotResult) => captureScreenshotResult.ToByteArray(); - public byte[] ToByteArray() => System.Convert.FromBase64String(Data); + public byte[] ToByteArray() => Data.ToArray(); } diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs index d9180f9ecc59b..710069ee9e163 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs @@ -112,7 +112,7 @@ public static implicit operator PrintPageRange(Range range) #endif } -public sealed record PrintResult(string Data) : EmptyResult +public sealed record PrintResult(ReadOnlyMemory Data) : EmptyResult { - public byte[] ToByteArray() => Convert.FromBase64String(Data); + public byte[] ToByteArray() => Data.ToArray(); } diff --git a/dotnet/src/webdriver/BiDi/Network/BytesValue.cs b/dotnet/src/webdriver/BiDi/Network/BytesValue.cs index 9952bff13f1c2..8d57fb7b52f0f 100644 --- a/dotnet/src/webdriver/BiDi/Network/BytesValue.cs +++ b/dotnet/src/webdriver/BiDi/Network/BytesValue.cs @@ -28,9 +28,9 @@ namespace OpenQA.Selenium.BiDi.Network; public abstract record BytesValue { public static implicit operator BytesValue(string value) => new StringBytesValue(value); - public static implicit operator BytesValue(byte[] value) => new Base64BytesValue(Convert.ToBase64String(value)); + public static implicit operator BytesValue(byte[] value) => new Base64BytesValue(value); } public sealed record StringBytesValue(string Value) : BytesValue; -public sealed record Base64BytesValue(string Value) : BytesValue; +public sealed record Base64BytesValue(ReadOnlyMemory Value) : BytesValue; diff --git a/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs b/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs index 4092203c47bac..8027787d72eec 100644 --- a/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs +++ b/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using System; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.WebExtension; @@ -35,7 +36,7 @@ public abstract record ExtensionData; public sealed record ExtensionArchivePath(string Path) : ExtensionData; -public sealed record ExtensionBase64Encoded(string Value) : ExtensionData; +public sealed record ExtensionBase64Encoded(ReadOnlyMemory Value) : ExtensionData; public sealed record ExtensionPath(string Path) : ExtensionData; diff --git a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index 1ee5cf6216c63..ed10187f7e045 100644 --- a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -250,7 +250,7 @@ public async Task CanCaptureScreenshot() var screenshot = await context.CaptureScreenshotAsync(); Assert.That(screenshot, Is.Not.Null); - Assert.That(screenshot.Data, Is.Not.Empty); + Assert.That(screenshot.Data.Length, Is.Not.Zero); } [Test] @@ -263,7 +263,7 @@ public async Task CanCaptureScreenshotWithParameters() }); Assert.That(screenshot, Is.Not.Null); - Assert.That(screenshot.Data, Is.Not.Empty); + Assert.That(screenshot.Data.Length, Is.Not.Zero); } [Test] @@ -276,7 +276,7 @@ public async Task CanCaptureScreenshotOfViewport() }); Assert.That(screenshot, Is.Not.Null); - Assert.That(screenshot.Data, Is.Not.Empty); + Assert.That(screenshot.Data.Length, Is.Not.Zero); } [Test] @@ -292,7 +292,7 @@ public async Task CanCaptureScreenshotOfElement() }); Assert.That(screenshot, Is.Not.Null); - Assert.That(screenshot.Data, Is.Not.Empty); + Assert.That(screenshot.Data.Length, Is.Not.Zero); } [Test] @@ -313,6 +313,6 @@ public async Task CanPrintPage() var pdf = await context.PrintAsync(); Assert.That(pdf, Is.Not.Null); - Assert.That(pdf.Data, Is.Not.Empty); + Assert.That(pdf.Data.Length, Is.Not.Zero); } } diff --git a/dotnet/test/common/BiDi/WebExtension/WebExtensionTest.cs b/dotnet/test/common/BiDi/WebExtension/WebExtensionTest.cs index 4be01281dc79c..327ce5d4d29f3 100644 --- a/dotnet/test/common/BiDi/WebExtension/WebExtensionTest.cs +++ b/dotnet/test/common/BiDi/WebExtension/WebExtensionTest.cs @@ -64,9 +64,9 @@ public async Task CanInstallBase64WebExtension() { var path = LocateRelativePath("common/extensions/webextensions-selenium-example.zip"); - string base64 = Convert.ToBase64String(File.ReadAllBytes(path)); + var bytes = File.ReadAllBytes(path); - var result = await bidi.WebExtension.InstallAsync(new ExtensionBase64Encoded(base64)); + var result = await bidi.WebExtension.InstallAsync(new ExtensionBase64Encoded(bytes)); Assert.That(result, Is.Not.Null); Assert.That(result.Extension, Is.Not.Null);