Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public Task<PrintResult> PrintAsync(PrintOptions? options = null, CancellationTo
return BiDi.BrowsingContext.PrintAsync(this, options, cancellationToken);
}

public Task<StartScreencastResult> StartScreencastAsync(StartScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
return BiDi.BrowsingContext.StartScreencastAsync(this, options, cancellationToken);
}

public Task<HandleUserPromptResult> HandleUserPromptAsync(HandleUserPromptOptions? options = null, CancellationToken cancellationToken = default)
{
return BiDi.BrowsingContext.HandleUserPromptAsync(this, options, cancellationToken);
Expand Down
24 changes: 24 additions & 0 deletions dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ internal sealed class BrowsingContextModule : Module, IBrowsingContextModule
private static readonly Command<HandleUserPromptParameters, HandleUserPromptResult> HandleUserPromptCommand = new(
"browsingContext.handleUserPrompt", Default.HandleUserPromptParameters, Default.HandleUserPromptResult);

private static readonly Command<StartScreencastParameters, StartScreencastResult> StartScreencastCommand = new(
"browsingContext.startScreencast", Default.StartScreencastParameters, Default.StartScreencastResult);

private static readonly Command<StopScreencastParameters, StopScreencastResult> StopScreencastCommand = new(
"browsingContext.stopScreencast", Default.StopScreencastParameters, Default.StopScreencastResult);

public async Task<CreateResult> CreateAsync(ContextType type, CreateOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new CreateParameters(type, options?.ReferenceContext, options?.Background, options?.UserContext);
Expand Down Expand Up @@ -144,6 +150,20 @@ public async Task<HandleUserPromptResult> HandleUserPromptAsync(BrowsingContext
return await ExecuteAsync(HandleUserPromptCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<StartScreencastResult> StartScreencastAsync(BrowsingContext context, StartScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new StartScreencastParameters(context, options?.MimeType, options?.Video, options?.Audio);

return await ExecuteAsync(StartScreencastCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<StopScreencastResult> StopScreencastAsync(Screencast screencast, StopScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new StopScreencastParameters(screencast);

return await ExecuteAsync(StopScreencastCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public IEventSource<NavigationStartedEventArgs> NavigationStarted => _navigationStarted ?? Interlocked.CompareExchange(ref _navigationStarted, CreateEventSource(BrowsingContextEvent.NavigationStarted), null) ?? _navigationStarted;
private IEventSource<NavigationStartedEventArgs>? _navigationStarted;

Expand Down Expand Up @@ -209,6 +229,10 @@ public async Task<HandleUserPromptResult> HandleUserPromptAsync(BrowsingContext
[JsonSerializable(typeof(ReloadResult))]
[JsonSerializable(typeof(SetViewportParameters))]
[JsonSerializable(typeof(SetViewportResult))]
[JsonSerializable(typeof(StartScreencastParameters))]
[JsonSerializable(typeof(StartScreencastResult))]
[JsonSerializable(typeof(StopScreencastParameters))]
[JsonSerializable(typeof(StopScreencastResult))]
[JsonSerializable(typeof(TraverseHistoryParameters))]
[JsonSerializable(typeof(TraverseHistoryResult))]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public interface IBrowsingContextModule
Task<PrintResult> PrintAsync(BrowsingContext context, PrintOptions? options = null, CancellationToken cancellationToken = default);
Task<ReloadResult> ReloadAsync(BrowsingContext context, ReloadOptions? options = null, CancellationToken cancellationToken = default);
Task<SetViewportResult> SetViewportAsync(SetViewportOptions? options = null, CancellationToken cancellationToken = default);
Task<StartScreencastResult> StartScreencastAsync(BrowsingContext context, StartScreencastOptions? options = null, CancellationToken cancellationToken = default);
Task<StopScreencastResult> StopScreencastAsync(Screencast screencast, StopScreencastOptions? options = null, CancellationToken cancellationToken = default);
Task<TraverseHistoryResult> TraverseHistoryAsync(BrowsingContext context, int delta, TraverseHistoryOptions? options = null, CancellationToken cancellationToken = default);
}
68 changes: 68 additions & 0 deletions dotnet/src/webdriver/BiDi/BrowsingContext/Screencast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// <copyright file="Screencast.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json.Serialization;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi.BrowsingContext;

[JsonConverter(typeof(Converter))]
public sealed record Screencast : IIdentifiable
{
public Screencast(IBiDi bidi, string id)
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
{
ArgumentNullException.ThrowIfNull(bidi);
BiDi = bidi;
Id = id;
}

public string Id { get; }

[JsonIgnore]
public IBiDi BiDi { get; }

public Task<StopScreencastResult> StopAsync(StopScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
return BiDi.BrowsingContext.StopScreencastAsync(this, options, cancellationToken);
}

public bool Equals(Screencast? other)
{
return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal);
}

public override int GetHashCode()
{
return StringComparer.Ordinal.GetHashCode(Id);
}

[SuppressMessage("CodeQuality", "IDE0051", Justification = "Used by compiler-generated ToString()")]
private bool PrintMembers(StringBuilder builder)
{
builder.Append($"Id = {Id}");
return true;
}

public sealed class Converter : IdentifiableConverter<Screencast>
{
protected override Screencast Create(IBiDi bidi, string id) => new(bidi, id);
}
}
42 changes: 42 additions & 0 deletions dotnet/src/webdriver/BiDi/BrowsingContext/StartScreencast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <copyright file="StartScreencast.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

namespace OpenQA.Selenium.BiDi.BrowsingContext;

internal sealed record StartScreencastParameters(BrowsingContext Context, string? MimeType, MediaTrackConstraints? Video, bool? Audio) : Parameters;

public sealed record StartScreencastOptions : CommandOptions
{
public string? MimeType { get; init; }

public MediaTrackConstraints? Video { get; init; }

public bool? Audio { get; init; }
}

public record struct MediaTrackConstraints
{
public long? Width { get; init; }

public long? Height { get; init; }

public long? FrameRate { get; init; }
}

public sealed record StartScreencastResult(Screencast Screencast, string Path) : EmptyResult;
26 changes: 26 additions & 0 deletions dotnet/src/webdriver/BiDi/BrowsingContext/StopScreencast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="StopScreencast.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

namespace OpenQA.Selenium.BiDi.BrowsingContext;

internal sealed record StopScreencastParameters(Screencast Screencast) : Parameters;

public sealed record StopScreencastOptions : CommandOptions;

public sealed record StopScreencastResult(string Path, string? Error) : EmptyResult;
16 changes: 16 additions & 0 deletions dotnet/test/webdriver/BiDi/BrowsingContext/BrowsingContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,20 @@ public async Task CanPrintPage()
Assert.That(pdf, Is.Not.Null);
Assert.That(pdf.Data.Length, Is.Not.Zero);
}

[Test]
[IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")]
[IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")]
public async Task CanStartAndStopScreencast()
{
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
var startScreencastResult = await context.StartScreencastAsync();

Assert.That(startScreencastResult.Screencast, Is.Not.Null);
Assert.That(startScreencastResult.Path, Is.Not.Empty);

var stopScreencastResult = await startScreencastResult.Screencast.StopAsync();

Assert.That(stopScreencastResult.Path, Is.EqualTo(startScreencastResult.Path));
Comment thread
nvborisenko marked this conversation as resolved.
Resolved
Assert.That(stopScreencastResult.Error, Is.Null);
}
}
Loading