diff --git a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs index a3a804094fe44..0c3e44db81e0b 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs @@ -70,6 +70,13 @@ public async Task SetScreenOrientationOverri return await Broker.ExecuteCommandAsync(new SetScreenOrientationOverrideCommand(@params), options, _jsonContext.SetScreenOrientationOverrideCommand, _jsonContext.SetScreenOrientationOverrideResult).ConfigureAwait(false); } + public async Task SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null) + { + var @params = new SetScreenSettingsOverrideParameters(screenArea, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetScreenSettingsOverrideCommand(@params), options, _jsonContext.SetScreenSettingsOverrideCommand, _jsonContext.SetScreenSettingsOverrideResult).ConfigureAwait(false); + } + public async Task SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null) { var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed); @@ -114,6 +121,8 @@ protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) [JsonSerializable(typeof(SetScriptingEnabledResult))] [JsonSerializable(typeof(SetScreenOrientationOverrideCommand))] [JsonSerializable(typeof(SetScreenOrientationOverrideResult))] +[JsonSerializable(typeof(SetScreenSettingsOverrideCommand))] +[JsonSerializable(typeof(SetScreenSettingsOverrideResult))] [JsonSerializable(typeof(SetGeolocationOverrideCommand))] [JsonSerializable(typeof(SetGeolocationOverrideResult))] diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs new file mode 100644 index 0000000000000..29da3b4be55c9 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs @@ -0,0 +1,39 @@ +// +// 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.Collections.Generic; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetScreenSettingsOverrideCommand(SetScreenSettingsOverrideParameters @params) + : Command(@params, "emulation.setScreenSettingsOverride"); + +internal sealed record SetScreenSettingsOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenArea? ScreenArea, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetScreenSettingsOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} + +public sealed record ScreenArea(long Width, long Height); + +public sealed record SetScreenSettingsOverrideResult : EmptyResult; diff --git a/dotnet/test/common/BiDi/Emulation/EmulationTest.cs b/dotnet/test/common/BiDi/Emulation/EmulationTest.cs index 03d42b5822d4a..0f5c79295a452 100644 --- a/dotnet/test/common/BiDi/Emulation/EmulationTest.cs +++ b/dotnet/test/common/BiDi/Emulation/EmulationTest.cs @@ -167,6 +167,21 @@ public void CanSetScreenOrientationOverrideToDefault() Throws.Nothing); } + [Test] + [IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public void CanSetScreenSettingsOverride() + { + var screenArea = new ScreenArea(300, 200); + + Assert.That(async () => + { + await bidi.Emulation.SetScreenSettingsOverrideAsync(screenArea, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + [Test] public void CanSetGeolocationCoordinatesOverride() {