From 9ab73e49be1250487af4d454566b3f8e9b863543 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:19:33 +0300 Subject: [PATCH] [dotnet] [bidi] Add SetScrollbarTypeOverride command in Emulation module --- .../BiDi/Emulation/EmulationModule.cs | 9 ++++ .../BiDi/Emulation/IEmulationModule.cs | 1 + .../SetScrollbarTypeOverrideCommand.cs | 44 +++++++++++++++++++ .../common/BiDi/Emulation/EmulationTests.cs | 20 +++++++++ 4 files changed, 74 insertions(+) create mode 100644 dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs diff --git a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs index a6d6dab6107df..013fbca7c25f9 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs @@ -76,6 +76,13 @@ public async Task SetScreenSettingsOverrideAsyn return await ExecuteCommandAsync(new SetScreenSettingsOverrideCommand(@params), options, _jsonContext.SetScreenSettingsOverrideCommand, _jsonContext.SetScreenSettingsOverrideResult, cancellationToken).ConfigureAwait(false); } + public async Task SetScrollbarTypeOverrideAsync(ScrollbarType? scrollbarType, SetScrollbarTypeOverrideOptions? options = null, CancellationToken cancellationToken = default) + { + var @params = new SetScrollbarTypeOverrideParameters(scrollbarType, options?.Contexts, options?.UserContexts); + + return await ExecuteCommandAsync(new SetScrollbarTypeOverrideCommand(@params), options, _jsonContext.SetScrollbarTypeOverrideCommand, _jsonContext.SetScrollbarTypeOverrideResult, cancellationToken).ConfigureAwait(false); + } + public async Task SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null, CancellationToken cancellationToken = default) { var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed); @@ -136,6 +143,8 @@ protected override void Initialize(IBiDi bidi, JsonSerializerOptions jsonSeriali [JsonSerializable(typeof(SetScreenOrientationOverrideResult))] [JsonSerializable(typeof(SetScreenSettingsOverrideCommand))] [JsonSerializable(typeof(SetScreenSettingsOverrideResult))] +[JsonSerializable(typeof(SetScrollbarTypeOverrideCommand))] +[JsonSerializable(typeof(SetScrollbarTypeOverrideResult))] [JsonSerializable(typeof(SetGeolocationOverrideCommand))] [JsonSerializable(typeof(SetGeolocationOverrideResult))] [JsonSerializable(typeof(SetTouchOverrideCommand))] diff --git a/dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs index 3b157b0876356..20ef789ab1cff 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs @@ -29,6 +29,7 @@ public interface IEmulationModule Task SetNetworkConditionsAsync(NetworkConditions? networkConditions, SetNetworkConditionsOptions? options = null, CancellationToken cancellationToken = default); Task SetScreenOrientationOverrideAsync(ScreenOrientation? screenOrientation, SetScreenOrientationOverrideOptions? options = null, CancellationToken cancellationToken = default); Task SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null, CancellationToken cancellationToken = default); + Task SetScrollbarTypeOverrideAsync(ScrollbarType? scrollbarType, SetScrollbarTypeOverrideOptions? options = null, CancellationToken cancellationToken = default); Task SetScriptingEnabledAsync(bool? enabled, SetScriptingEnabledOptions? options = null, CancellationToken cancellationToken = default); Task SetTimezoneOverrideAsync(string? timezone, SetTimezoneOverrideOptions? options = null, CancellationToken cancellationToken = default); Task SetTouchOverrideAsync(long? maxTouchPoints, SetTouchOverrideOptions? options = null, CancellationToken cancellationToken = default); diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs new file mode 100644 index 0000000000000..190d2411edbfc --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs @@ -0,0 +1,44 @@ +// +// 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. +// + +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Json.Converters; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetScrollbarTypeOverrideCommand(SetScrollbarTypeOverrideParameters @params) + : Command(@params, "emulation.setScrollbarTypeOverride"); + +internal sealed record SetScrollbarTypeOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScrollbarType? ScrollbarType, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed record SetScrollbarTypeOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; init; } + + public IEnumerable? UserContexts { get; init; } +} + +[JsonConverter(typeof(CamelCaseEnumConverter))] +public enum ScrollbarType +{ + Classic, + Overlay +} + +public sealed record SetScrollbarTypeOverrideResult : EmptyResult; diff --git a/dotnet/test/common/BiDi/Emulation/EmulationTests.cs b/dotnet/test/common/BiDi/Emulation/EmulationTests.cs index 16db4e621f52f..4febce379ef6a 100644 --- a/dotnet/test/common/BiDi/Emulation/EmulationTests.cs +++ b/dotnet/test/common/BiDi/Emulation/EmulationTests.cs @@ -131,6 +131,26 @@ public void CanSetScriptingEnabledToDefault() Throws.Nothing); } + [Test] + public void CanSetScrollbarTypeOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetScrollbarTypeOverrideAsync(ScrollbarType.Overlay, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + public void CanSetScrollbarTypeOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetScrollbarTypeOverrideAsync(null, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + [Test] public void CanSetScreenOrientationOverride() {