From 1bed17606b0ad27716edea285d319e2642f77b9a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:30:59 +0000 Subject: [PATCH 01/18] Bump Selenium.WebDriver from 4.25.0 to 4.26.1 in /src Bumps [Selenium.WebDriver](https://github.com/SeleniumHQ/selenium) from 4.25.0 to 4.26.1. - [Release notes](https://github.com/SeleniumHQ/selenium/releases) - [Commits](https://github.com/SeleniumHQ/selenium/commits) --- updated-dependencies: - dependency-name: Selenium.WebDriver dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index df24c62..0b4b494 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -12,7 +12,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 5dd94b657f66af048b24fd98626bad373f26078c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:31:13 +0000 Subject: [PATCH 02/18] Bump GitVersion.MsBuild from 6.0.3 to 6.0.4 in /src Bumps [GitVersion.MsBuild](https://github.com/GitTools/GitVersion) from 6.0.3 to 6.0.4. - [Release notes](https://github.com/GitTools/GitVersion/releases) - [Changelog](https://github.com/GitTools/GitVersion/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/GitTools/GitVersion/compare/6.0.3...6.0.4) --- updated-dependencies: - dependency-name: GitVersion.MsBuild dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index fc174d6..240ad17 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From d66f5f4b3388336f7fa8899b5eb696dba557501c Mon Sep 17 00:00:00 2001 From: aristotelos Date: Tue, 5 Nov 2024 11:17:54 +0100 Subject: [PATCH 03/18] Add scroll script and fix other Windows extensions Add the `windows: scroll` extension script for compatibility with appium-windows-driver. Document the other Windows extension scripts and throw on unsupported options. Also fix the calculation of the mouse position by element ID and x and y coordinates. --- README.md | 4 + .../Controllers/ExecuteController.cs | 19 ++- .../Models/WindowsClickScript.cs | 4 + .../Models/WindowsHoverScript.cs | 1 + .../Models/WindowsScrollScript.cs | 12 ++ .../Services/IWindowsExtensionService.cs | 1 + .../Services/WindowsExtensionService.cs | 111 +++++++++++------- 7 files changed, 110 insertions(+), 42 deletions(-) create mode 100644 src/FlaUI.WebDriver/Models/WindowsScrollScript.cs diff --git a/README.md b/README.md index 8448c6b..f10bd76 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,10 @@ Using the WebdriverIO JavaScript client: const result = driver.executeScript("powerShell", [{ command: `1+1` }]); ``` +## Windows extensions + +To enable easy switching from appium-windows-driver, there is a rudimentary implementation of `windows: click`, `windows: hover`, `windows: scroll` and `windows: keys`. + ## Supported WebDriver Commands | Method | URI Template | Command | Implemented | diff --git a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs index 6a45bc3..4502de0 100644 --- a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs +++ b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs @@ -35,8 +35,10 @@ public async Task ExecuteScript([FromRoute] string sessionId, [Fro return await ExecuteWindowsClickScript(session, executeScriptRequest); case "windows: hover": return await ExecuteWindowsHoverScript(session, executeScriptRequest); + case "windows: scroll": + return await ExecuteWindowsScrollScript(session, executeScriptRequest); default: - throw WebDriverResponseException.UnsupportedOperation("Only 'powerShell' scripts are supported"); + throw WebDriverResponseException.UnsupportedOperation("Only 'powerShell', 'windows: keys', 'windows: click', 'windows: hover' scripts are supported"); } } @@ -103,6 +105,21 @@ private async Task ExecuteWindowsClickScript(Session session, Exec return WebDriverResult.Success(); } + private async Task ExecuteWindowsScrollScript(Session session, ExecuteScriptRequest executeScriptRequest) + { + if (executeScriptRequest.Args.Count != 1) + { + throw WebDriverResponseException.InvalidArgument($"Expected an array of exactly 1 arguments for the windows: click script, but got {executeScriptRequest.Args.Count} arguments"); + } + var action = JsonSerializer.Deserialize(executeScriptRequest.Args[0], new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + if (action == null) + { + throw WebDriverResponseException.InvalidArgument("Action cannot be null"); + } + await _windowsExtensionService.ExecuteScrollScript(session, action); + return WebDriverResult.Success(); + } + private async Task ExecuteWindowsHoverScript(Session session, ExecuteScriptRequest executeScriptRequest) { if (executeScriptRequest.Args.Count != 1) diff --git a/src/FlaUI.WebDriver/Models/WindowsClickScript.cs b/src/FlaUI.WebDriver/Models/WindowsClickScript.cs index 25df7c9..e960fca 100644 --- a/src/FlaUI.WebDriver/Models/WindowsClickScript.cs +++ b/src/FlaUI.WebDriver/Models/WindowsClickScript.cs @@ -6,5 +6,9 @@ public class WindowsClickScript public int? X { get; set; } public int? Y { get; set; } public string? Button { get; set; } + public string[]? ModifierKeys { get; set; } + public int? DurationMs { get; set; } + public int? Times { get; set; } + public int? InterClickDelayMs { get; set; } } } \ No newline at end of file diff --git a/src/FlaUI.WebDriver/Models/WindowsHoverScript.cs b/src/FlaUI.WebDriver/Models/WindowsHoverScript.cs index faa4b76..d5fa505 100644 --- a/src/FlaUI.WebDriver/Models/WindowsHoverScript.cs +++ b/src/FlaUI.WebDriver/Models/WindowsHoverScript.cs @@ -9,5 +9,6 @@ public class WindowsHoverScript public int? EndY { get; set; } public string? EndElementId { get; set; } public int? DurationMs { get; set; } + public string[]? ModifierKeys { get; set; } } } \ No newline at end of file diff --git a/src/FlaUI.WebDriver/Models/WindowsScrollScript.cs b/src/FlaUI.WebDriver/Models/WindowsScrollScript.cs new file mode 100644 index 0000000..08f536d --- /dev/null +++ b/src/FlaUI.WebDriver/Models/WindowsScrollScript.cs @@ -0,0 +1,12 @@ +namespace FlaUI.WebDriver.Models +{ + public class WindowsScrollScript + { + public string? ElementId { get; set; } + public int? X { get; set; } + public int? Y { get; set; } + public int? DeltaX { get; set; } + public int? DeltaY { get; set; } + public string[]? ModifierKeys { get; set; } + } +} \ No newline at end of file diff --git a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs index 9b6e2dd..340b067 100644 --- a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs @@ -5,6 +5,7 @@ namespace FlaUI.WebDriver.Services public interface IWindowsExtensionService { Task ExecuteClickScript(Session session, WindowsClickScript action); + Task ExecuteScrollScript(Session session, WindowsScrollScript action); Task ExecuteHoverScript(Session session, WindowsHoverScript action); Task ExecuteKeyScript(Session session, WindowsKeyScript action); } diff --git a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs index ee25b0f..d10ae20 100644 --- a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs @@ -1,4 +1,5 @@ using FlaUI.Core.Input; +using FlaUI.Core.Tools; using FlaUI.Core.WindowsAPI; using FlaUI.WebDriver.Models; using System.Drawing; @@ -16,76 +17,104 @@ public WindowsExtensionService(ILogger logger) public async Task ExecuteClickScript(Session session, WindowsClickScript action) { - var mouseButton = action.Button != null ? Enum.Parse(action.Button, true) : MouseButton.Left; - if (action.ElementId != null) + if (action.DurationMs.HasValue) { - var element = session.FindKnownElementById(action.ElementId); - if (element == null) - { - throw WebDriverResponseException.ElementNotFound(action.ElementId); - } - _logger.LogDebug("Clicking element {ElementId} with mouse button {MouseButton}", action.ElementId, mouseButton); - Mouse.Click(element.BoundingRectangle.Location, mouseButton); + throw WebDriverResponseException.UnsupportedOperation("Duration is not yet supported"); } - else if (action.X.HasValue && action.Y.HasValue) + if (action.Times.HasValue) { - _logger.LogDebug("Clicking point ({X}, {Y}) with mouse button {MouseButton}", action.X.Value, action.Y.Value, mouseButton); - Mouse.Click(new Point { X = action.X.Value, Y = action.Y.Value }, mouseButton); + throw WebDriverResponseException.UnsupportedOperation("Times is not yet supported"); } - else + if (action.ModifierKeys != null) { - throw WebDriverResponseException.InvalidArgument("Either \"elementId\" or \"x\" and \"y\" must be provided"); + throw WebDriverResponseException.UnsupportedOperation("Modifier keys are not yet supported"); } + var point = GetPoint(action.ElementId, action.X, action.Y, session); + var mouseButton = action.Button != null ? Enum.Parse(action.Button, true) : MouseButton.Left; + _logger.LogDebug("Clicking point ({X}, {Y}) with mouse button {MouseButton}", point.X, point.Y, mouseButton); + Mouse.Click(point, mouseButton); await Task.Yield(); } - public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) + public async Task ExecuteScrollScript(Session session, WindowsScrollScript action) { - if (action.StartX.HasValue && action.StartY.HasValue) + if (action.ModifierKeys != null) { - _logger.LogDebug("Moving mouse to ({X}, {Y})", action.StartX.Value, action.StartY.Value); - Mouse.MoveTo(action.StartX.Value, action.StartY.Value); + throw WebDriverResponseException.UnsupportedOperation("Modifier keys are not yet supported"); } - else if (action.StartElementId != null) + var point = GetPoint(action.ElementId, action.X, action.Y, session); + _logger.LogDebug("Scrolling at point ({X}, {Y})", point.X, point.Y); + Mouse.Position = point; + if (action.DeltaY.HasValue && action.DeltaY.Value != 0) { - var element = session.FindKnownElementById(action.StartElementId); + Mouse.Scroll(action.DeltaY.Value); + } + if (action.DeltaX.HasValue && action.DeltaX.Value != 0) + { + Mouse.HorizontalScroll(-action.DeltaX.Value); + } + await Task.Yield(); + } + + private Point GetPoint(string? elementId, int? x, int? y, Session session) + { + if (elementId != null) + { + var element = session.FindKnownElementById(elementId); if (element == null) { - throw WebDriverResponseException.ElementNotFound(action.StartElementId); + throw WebDriverResponseException.ElementNotFound(elementId); } - _logger.LogDebug("Moving mouse to element {ElementId}", action.StartElementId); - Mouse.MoveTo(element.BoundingRectangle.Location); + + if (x.HasValue && y.HasValue) + { + return new Point + { + X = element.BoundingRectangle.Left + x.Value, + Y = element.BoundingRectangle.Top + y.Value + }; + } + + return element.BoundingRectangle.Center(); } - else + + if (x.HasValue && y.HasValue) { - throw WebDriverResponseException.InvalidArgument("Either \"startElementId\" or \"startX\" and \"startY\" must be provided"); + return new Point { X = x.Value, Y = y.Value }; } + + throw WebDriverResponseException.InvalidArgument("Either element ID or x and y must be provided"); + } - if (action.DurationMs.HasValue) + public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) + { + if (action.ModifierKeys != null) { - _logger.LogDebug("Waiting for {DurationMs}ms", action.DurationMs.Value); - await Task.Delay(action.DurationMs.Value); + throw WebDriverResponseException.UnsupportedOperation("Modifier keys are not yet supported"); } + var startingPoint = GetPoint(action.StartElementId, action.StartX, action.StartY, session); + var endPoint = GetPoint(action.EndElementId, action.EndX, action.EndY, session); + + _logger.LogDebug("Moving mouse to starting point ({X}, {Y})", startingPoint.X, startingPoint.Y); + Mouse.Position = startingPoint; - if (action.EndX.HasValue && action.EndY.HasValue) + if (endPoint == startingPoint) { - _logger.LogDebug("Moving mouse to ({X}, {Y})", action.EndX.Value, action.EndY.Value); - Mouse.MoveTo(action.EndX.Value, action.EndY.Value); + // Hover for specified time + await Task.Delay(action.DurationMs ?? 100); + return; } - else if (action.EndElementId != null) + + _logger.LogDebug("Moving mouse to end point ({X}, {Y})", endPoint.X, endPoint.Y); + if (action.DurationMs.HasValue) { - var element = session.FindKnownElementById(action.EndElementId); - if (element == null) + if (action.DurationMs.Value <= 0) { - throw WebDriverResponseException.ElementNotFound(action.EndElementId); + throw WebDriverResponseException.UnsupportedOperation("Duration less than or equal to zero is not supported"); } - _logger.LogDebug("Moving mouse to element {ElementId}", action.EndElementId); - Mouse.MoveTo(element.BoundingRectangle.Location); - } - else - { - throw WebDriverResponseException.InvalidArgument("Either \"endElementId\" or \"endX\" and \"endY\" must be provided"); + Mouse.MovePixelsPerMillisecond = endPoint.Distance(startingPoint) / action.DurationMs.Value; } + Mouse.MoveTo(endPoint); } public async Task ExecuteKeyScript(Session session, WindowsKeyScript action) From bbb2406f26edfd13543ca6417c69e447e61dc869 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:48:03 +0000 Subject: [PATCH 04/18] Bump Swashbuckle.AspNetCore from 6.9.0 to 7.0.0 in /src Bumps [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) from 6.9.0 to 7.0.0. - [Release notes](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases) - [Commits](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/compare/v6.9.0...v7.0.0) --- updated-dependencies: - dependency-name: Swashbuckle.AspNetCore dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index 240ad17..f8adbc2 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -19,7 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From b00d9b9715f0b7d68449d3816395fc539d7f9853 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:48:23 +0000 Subject: [PATCH 05/18] Bump GitVersion.MsBuild from 6.0.4 to 6.0.5 in /src Bumps [GitVersion.MsBuild](https://github.com/GitTools/GitVersion) from 6.0.4 to 6.0.5. - [Release notes](https://github.com/GitTools/GitVersion/releases) - [Changelog](https://github.com/GitTools/GitVersion/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/GitTools/GitVersion/compare/6.0.4...6.0.5) --- updated-dependencies: - dependency-name: GitVersion.MsBuild dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index 240ad17..04a6e28 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From e3987daf3a1802f4a311d278b6538f42b119e14c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:13:06 +0000 Subject: [PATCH 06/18] Bump Appium.WebDriver and Selenium.WebDriver in /src Bumps [Appium.WebDriver](https://github.com/appium/dotnet-client) and [Selenium.WebDriver](https://github.com/SeleniumHQ/selenium). These dependencies needed to be updated together. Updates `Appium.WebDriver` from 6.0.0 to 6.0.1 - [Release notes](https://github.com/appium/dotnet-client/releases) - [Changelog](https://github.com/appium/dotnet-client/blob/main/CHANGELOG.MD) - [Commits](https://github.com/appium/dotnet-client/compare/v6.0.0...v6.0.1) Updates `Selenium.WebDriver` from 4.26.1 to 4.26.1 - [Release notes](https://github.com/SeleniumHQ/selenium/releases) - [Commits](https://github.com/SeleniumHQ/selenium/commits) --- updated-dependencies: - dependency-name: Appium.WebDriver dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Selenium.WebDriver dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 0b4b494..5c21744 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -8,7 +8,7 @@ - + From 689d6bb27910f245a96f631427459228ef253ca8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:51:13 +0000 Subject: [PATCH 07/18] Bump Microsoft.NET.Test.Sdk from 17.11.1 to 17.12.0 in /src Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.11.1 to 17.12.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.11.1...v17.12.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 5c21744..3463341 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj index 702181a..9dfb0db 100644 --- a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj +++ b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj @@ -8,7 +8,7 @@ - + From d1650bd1cadb47a1770c49ad10f0d73c7f28ed36 Mon Sep 17 00:00:00 2001 From: aristotelos Date: Wed, 20 Nov 2024 17:00:41 +0100 Subject: [PATCH 08/18] Add support for element property Treat element attributes and properties as equal, just like appium-windows-driver. --- README.md | 2 +- src/FlaUI.WebDriver.UITests/ElementTests.cs | 32 +++++++++++++++++++ .../Controllers/ElementController.cs | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f10bd76..4336114 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ To enable easy switching from appium-windows-driver, there is a rudimentary impl | GET | /session/{session id}/element/{element id}/selected | Is Element Selected | :white_check_mark: | | GET | /session/{session id}/element/{element id}/displayed | Is Element Displayed | :white_check_mark: [^isdisplayed] | | GET | /session/{session id}/element/{element id}/attribute/{name} | Get Element Attribute | :white_check_mark: [^getattribute] | -| GET | /session/{session id}/element/{element id}/property/{name} | Get Element Property | | +| GET | /session/{session id}/element/{element id}/property/{name} | Get Element Property | :white_check_mark: | | GET | /session/{session id}/element/{element id}/css/{property name} | Get Element CSS Value | N/A | | GET | /session/{session id}/element/{element id}/text | Get Element Text | :white_check_mark: | | GET | /session/{session id}/element/{element id}/name | Get Element Tag Name | :white_check_mark: | diff --git a/src/FlaUI.WebDriver.UITests/ElementTests.cs b/src/FlaUI.WebDriver.UITests/ElementTests.cs index 431c947..2f20192 100644 --- a/src/FlaUI.WebDriver.UITests/ElementTests.cs +++ b/src/FlaUI.WebDriver.UITests/ElementTests.cs @@ -366,6 +366,20 @@ public void GetAttribute_TextBox_ReturnsValue(string attributeName, string expec Assert.That(value, Is.EqualTo(expectedValue)); } + [TestCase(["ClassName", "TextBox"])] + [TestCase(["FrameworkId", "WPF"])] + [TestCase(["NonExistent", null])] + public void GetProperty_TextBox_ReturnsValue(string attributeName, string expectedValue) + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); + + var value = element.GetDomProperty(attributeName); + + Assert.That(value, Is.EqualTo(expectedValue)); + } + [Test] public void GetAttribute_DesktopElement_ReturnsAttribute() { @@ -395,5 +409,23 @@ public void GetAttribute_PatternProperty_ReturnsValue() Assert.That(value, Is.EqualTo("On")); } + + [Test] + public void GetProperty_PatternProperty_ReturnsValue() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + var element = driver.FindElement(ExtendedBy.AccessibilityId("SimpleCheckBox")); + + var value = element.GetDomProperty("Toggle.ToggleState"); + + Assert.That(value, Is.EqualTo("Off")); + + element.Click(); + + value = element.GetDomProperty("Toggle.ToggleState"); + + Assert.That(value, Is.EqualTo("On")); + } } } diff --git a/src/FlaUI.WebDriver/Controllers/ElementController.cs b/src/FlaUI.WebDriver/Controllers/ElementController.cs index 41d358c..de6b836 100644 --- a/src/FlaUI.WebDriver/Controllers/ElementController.cs +++ b/src/FlaUI.WebDriver/Controllers/ElementController.cs @@ -229,6 +229,7 @@ public async Task ElementSendKeys([FromRoute] string sessionId, [F } [HttpGet("{elementId}/attribute/{attributeId}")] + [HttpGet("{elementId}/property/{attributeId}")] public async Task GetAttribute([FromRoute] string sessionId, [FromRoute] string elementId, [FromRoute] string attributeId) { var session = GetSession(sessionId); From 70265148e6574b8cc99f72e4c02e0231a35375fd Mon Sep 17 00:00:00 2001 From: aristotelos Date: Wed, 20 Nov 2024 17:02:48 +0100 Subject: [PATCH 09/18] Add getClipboard and setClipboard extensions Add extensions that are also supported by appium-windows-driver. --- README.md | 2 +- src/FlaUI.WebDriver.UITests/ExecuteTests.cs | 32 ++++++++++ .../Controllers/ExecuteController.cs | 34 ++++++++++ .../Models/WindowsGetClipboardScript.cs | 7 ++ .../Models/WindowsSetClipboardScript.cs | 8 +++ .../Services/IWindowsExtensionService.cs | 2 + .../Services/WindowsExtensionService.cs | 64 +++++++++++++++++++ 7 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/FlaUI.WebDriver/Models/WindowsGetClipboardScript.cs create mode 100644 src/FlaUI.WebDriver/Models/WindowsSetClipboardScript.cs diff --git a/README.md b/README.md index 4336114..824ee5c 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ const result = driver.executeScript("powerShell", [{ command: `1+1` }]); ## Windows extensions -To enable easy switching from appium-windows-driver, there is a rudimentary implementation of `windows: click`, `windows: hover`, `windows: scroll` and `windows: keys`. +To enable easy switching from appium-windows-driver, there is a rudimentary implementation of `windows: click`, `windows: hover`, `windows: scroll`, `windows: keys`, `windows: getClipboard` and `windows: setClipboard`. ## Supported WebDriver Commands diff --git a/src/FlaUI.WebDriver.UITests/ExecuteTests.cs b/src/FlaUI.WebDriver.UITests/ExecuteTests.cs index 917b473..6380d81 100644 --- a/src/FlaUI.WebDriver.UITests/ExecuteTests.cs +++ b/src/FlaUI.WebDriver.UITests/ExecuteTests.cs @@ -1,5 +1,7 @@ using FlaUI.WebDriver.UITests.TestUtil; using NUnit.Framework; +using OpenQA.Selenium; +using OpenQA.Selenium.Interactions; using OpenQA.Selenium.Remote; using System.Collections.Generic; @@ -32,6 +34,36 @@ public void ExecuteScript_WindowsClickXY_IsSupported() Assert.That(activeElementText, Is.EqualTo("Test TextBox")); } + [Test] + public void ExecuteScript_WindowsGetClipboard_IsSupported() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); + element.Click(); + new Actions(driver).KeyDown(Keys.Control).SendKeys("a").KeyUp(Keys.Control).Perform(); + new Actions(driver).KeyDown(Keys.Control).SendKeys("c").KeyUp(Keys.Control).Perform(); + + var result = driver.ExecuteScript("windows: getClipboard", new Dictionary {}); + + Assert.That(result, Is.EqualTo("Test TextBox")); + } + + [Test] + public void ExecuteScript_WindowsSetClipboard_IsSupported() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + + var result = driver.ExecuteScript("windows: setClipboard", new Dictionary { + ["b64Content"] = "Pasted!"}); + + var element = driver.FindElement(ExtendedBy.AccessibilityId("TextBox")); + element.Click(); + new Actions(driver).KeyDown(Keys.Control).SendKeys("v").KeyUp(Keys.Control).Perform(); + Assert.That(element.Text, Is.EqualTo("Test TextBoxPasted!")); + } + [Test] public void ExecuteScript_WindowsHoverXY_IsSupported() { diff --git a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs index 4502de0..c6d6858 100644 --- a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs +++ b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs @@ -37,6 +37,10 @@ public async Task ExecuteScript([FromRoute] string sessionId, [Fro return await ExecuteWindowsHoverScript(session, executeScriptRequest); case "windows: scroll": return await ExecuteWindowsScrollScript(session, executeScriptRequest); + case "windows: setClipboard": + return await ExecuteWindowsSetClipboardScript(session, executeScriptRequest); + case "windows: getClipboard": + return await ExecuteWindowsGetClipboardScript(session, executeScriptRequest); default: throw WebDriverResponseException.UnsupportedOperation("Only 'powerShell', 'windows: keys', 'windows: click', 'windows: hover' scripts are supported"); } @@ -90,6 +94,36 @@ private async Task ExecutePowerShellScript(Session session, Execut return WebDriverResult.Success(result); } + private async Task ExecuteWindowsSetClipboardScript(Session session, ExecuteScriptRequest executeScriptRequest) + { + if (executeScriptRequest.Args.Count != 1) + { + throw WebDriverResponseException.InvalidArgument($"Expected an array of exactly 1 arguments for the windows: setClipboard script, but got {executeScriptRequest.Args.Count} arguments"); + } + var action = JsonSerializer.Deserialize(executeScriptRequest.Args[0], new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + if (action == null) + { + throw WebDriverResponseException.InvalidArgument("Action cannot be null"); + } + await _windowsExtensionService.ExecuteSetClipboardScript(session, action); + return WebDriverResult.Success(); + } + + private async Task ExecuteWindowsGetClipboardScript(Session session, ExecuteScriptRequest executeScriptRequest) + { + if (executeScriptRequest.Args.Count != 1) + { + throw WebDriverResponseException.InvalidArgument($"Expected an array of exactly 1 arguments for the windows: getClipboard script, but got {executeScriptRequest.Args.Count} arguments"); + } + var action = JsonSerializer.Deserialize(executeScriptRequest.Args[0], new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + if (action == null) + { + throw WebDriverResponseException.InvalidArgument("Action cannot be null"); + } + var result = await _windowsExtensionService.ExecuteGetClipboardScript(session, action); + return WebDriverResult.Success(result); + } + private async Task ExecuteWindowsClickScript(Session session, ExecuteScriptRequest executeScriptRequest) { if (executeScriptRequest.Args.Count != 1) diff --git a/src/FlaUI.WebDriver/Models/WindowsGetClipboardScript.cs b/src/FlaUI.WebDriver/Models/WindowsGetClipboardScript.cs new file mode 100644 index 0000000..286101a --- /dev/null +++ b/src/FlaUI.WebDriver/Models/WindowsGetClipboardScript.cs @@ -0,0 +1,7 @@ +namespace FlaUI.WebDriver.Models +{ + public class WindowsGetClipboardScript + { + public string? ContentType { get; set; } + } +} diff --git a/src/FlaUI.WebDriver/Models/WindowsSetClipboardScript.cs b/src/FlaUI.WebDriver/Models/WindowsSetClipboardScript.cs new file mode 100644 index 0000000..3aad501 --- /dev/null +++ b/src/FlaUI.WebDriver/Models/WindowsSetClipboardScript.cs @@ -0,0 +1,8 @@ +namespace FlaUI.WebDriver.Models +{ + public class WindowsSetClipboardScript + { + public string B64Content { get; set; } = ""; + public string? ContentType { get; set; } + } +} diff --git a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs index 340b067..f2abe95 100644 --- a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs @@ -8,5 +8,7 @@ public interface IWindowsExtensionService Task ExecuteScrollScript(Session session, WindowsScrollScript action); Task ExecuteHoverScript(Session session, WindowsHoverScript action); Task ExecuteKeyScript(Session session, WindowsKeyScript action); + Task ExecuteGetClipboardScript(Session session, WindowsGetClipboardScript action); + Task ExecuteSetClipboardScript(Session session, WindowsSetClipboardScript action); } } \ No newline at end of file diff --git a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs index d10ae20..b3067e4 100644 --- a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs @@ -15,6 +15,70 @@ public WindowsExtensionService(ILogger logger) _logger = logger; } + public Task ExecuteGetClipboardScript(Session session, WindowsGetClipboardScript action) + { + switch(action.ContentType) + { + default: + case "plaintext": + return Task.FromResult(ExecuteOnClipboardThread( + () => System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.UnicodeText) + )); + case "image": + return Task.FromResult(ExecuteOnClipboardThread(() => + { + using var image = System.Windows.Forms.Clipboard.GetImage(); + if (image == null) + { + return ""; + } + using var stream = new MemoryStream(); + image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); + return Convert.ToBase64String(stream.ToArray()); + })); + } + } + + public Task ExecuteSetClipboardScript(Session session, WindowsSetClipboardScript action) + { + switch (action.ContentType) + { + default: + case "plaintext": + ExecuteOnClipboardThread(() => System.Windows.Forms.Clipboard.SetText(action.B64Content)); + break; + case "image": + ExecuteOnClipboardThread(() => + { + using var stream = new MemoryStream(Convert.FromBase64String(action.B64Content)); + using var image = Image.FromStream(stream); + System.Windows.Forms.Clipboard.SetImage(image); + }); + break; + } + return Task.CompletedTask; + } + + private void ExecuteOnClipboardThread(System.Action action) + { + // See https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.clipboard?view=windowsdesktop-8.0#remarks + var thread = new Thread(() => action()); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + thread.Join(); + } + + private string ExecuteOnClipboardThread(Func method) + { + // See https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.clipboard?view=windowsdesktop-8.0#remarks + string result = ""; + var thread = new Thread(() => { result = method(); }); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + thread.Join(); + return result; + } + public async Task ExecuteClickScript(Session session, WindowsClickScript action) { if (action.DurationMs.HasValue) From aa6ad425ec5ab34581a62dedf0939c684e9d68d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:05:57 +0000 Subject: [PATCH 10/18] Bump Swashbuckle.AspNetCore from 7.0.0 to 7.1.0 in /src Bumps [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) from 7.0.0 to 7.1.0. - [Release notes](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases) - [Commits](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/compare/v7.0.0...v7.1.0) --- updated-dependencies: - dependency-name: Swashbuckle.AspNetCore dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index a1d0d9a..de51bfe 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -19,7 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 01fd1002abeb64bf7cceb1e0fa7783bfd982c7c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:41:18 +0000 Subject: [PATCH 11/18] Bump Swashbuckle.AspNetCore from 7.1.0 to 7.2.0 in /src Bumps [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) from 7.1.0 to 7.2.0. - [Release notes](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases) - [Commits](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/compare/v7.1.0...v7.2.0) --- updated-dependencies: - dependency-name: Swashbuckle.AspNetCore dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index de51bfe..f920a59 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -19,7 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 275fa78b0d1b215c2a7b397d3093aeb0d6a7f757 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:12:57 +0000 Subject: [PATCH 12/18] Bump NUnit from 4.2.2 to 4.3.0 in /src Bumps [NUnit](https://github.com/nunit/nunit) from 4.2.2 to 4.3.0. - [Release notes](https://github.com/nunit/nunit/releases) - [Changelog](https://github.com/nunit/nunit/blob/main/CHANGES.md) - [Commits](https://github.com/nunit/nunit/compare/4.2.2...4.3.0) --- updated-dependencies: - dependency-name: NUnit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 3463341..82884af 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj index 9dfb0db..b507699 100644 --- a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj +++ b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj @@ -9,7 +9,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From c6f00a0672caef506cb373e31a90c85b736ab8cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:58:14 +0000 Subject: [PATCH 13/18] Bump Selenium.WebDriver from 4.26.1 to 4.27.0 in /src Bumps [Selenium.WebDriver](https://github.com/SeleniumHQ/selenium) from 4.26.1 to 4.27.0. - [Release notes](https://github.com/SeleniumHQ/selenium/releases) - [Commits](https://github.com/SeleniumHQ/selenium/commits/selenium-4.27.0) --- updated-dependencies: - dependency-name: Selenium.WebDriver dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 82884af..79d4c02 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -12,7 +12,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 1c22f93671b1908291411131994fb66aa0b5ed39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:34:06 +0000 Subject: [PATCH 14/18] Bump NUnit from 4.3.0 to 4.3.1 in /src Bumps [NUnit](https://github.com/nunit/nunit) from 4.3.0 to 4.3.1. - [Release notes](https://github.com/nunit/nunit/releases) - [Changelog](https://github.com/nunit/nunit/blob/main/CHANGES.md) - [Commits](https://github.com/nunit/nunit/compare/4.3.0...4.3.1) --- updated-dependencies: - dependency-name: NUnit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 82884af..5c71e5a 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj index b507699..e26d99f 100644 --- a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj +++ b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj @@ -9,7 +9,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From 796056f161fc3d34db54206ed44e2293bb3c7672 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:33:23 +0000 Subject: [PATCH 15/18] Bump NUnit from 4.3.1 to 4.3.2 in /src Bumps [NUnit](https://github.com/nunit/nunit) from 4.3.1 to 4.3.2. - [Release notes](https://github.com/nunit/nunit/releases) - [Changelog](https://github.com/nunit/nunit/blob/main/CHANGES.md) - [Commits](https://github.com/nunit/nunit/compare/4.3.1...4.3.2) --- updated-dependencies: - dependency-name: NUnit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 7b4ee81..d303945 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj index e26d99f..47de3e8 100644 --- a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj +++ b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj @@ -9,7 +9,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From 460a77792de03f37d720fa55dea541764f494680 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:33:42 +0000 Subject: [PATCH 16/18] Bump Appium.WebDriver and Selenium.WebDriver in /src Bumps [Appium.WebDriver](https://github.com/appium/dotnet-client) and [Selenium.WebDriver](https://github.com/SeleniumHQ/selenium). These dependencies needed to be updated together. Updates `Appium.WebDriver` from 6.0.1 to 7.0.0 - [Release notes](https://github.com/appium/dotnet-client/releases) - [Changelog](https://github.com/appium/dotnet-client/blob/main/CHANGELOG.MD) - [Commits](https://github.com/appium/dotnet-client/compare/v6.0.1...v7.0.0) Updates `Selenium.WebDriver` from 4.27.0 to 4.27.0 - [Release notes](https://github.com/SeleniumHQ/selenium/releases) - [Commits](https://github.com/SeleniumHQ/selenium/compare/selenium-4.27.0...selenium-4.27.0) --- updated-dependencies: - dependency-name: Appium.WebDriver dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Selenium.WebDriver dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 7b4ee81..7ac7d52 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -8,7 +8,7 @@ - + From 54126bffd70e55b877a5d4c449f48907a4470586 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:12:33 +0000 Subject: [PATCH 17/18] Bump coverlet.collector from 6.0.2 to 6.0.3 in /src Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 6.0.2 to 6.0.3. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/compare/v6.0.2...v6.0.3) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj | 2 +- src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index 7b4ee81..e71d5c6 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -13,7 +13,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj index e26d99f..835a68c 100644 --- a/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj +++ b/src/FlaUI.WebDriver.UnitTests/FlaUI.WebDriver.UnitTests.csproj @@ -11,7 +11,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 0dc5ec14ebfe4139bcb7710ca40ce57143f86b7f Mon Sep 17 00:00:00 2001 From: jensakejohansson Date: Thu, 16 Jan 2025 15:17:36 +0100 Subject: [PATCH 18/18] New message for the combined commit --- README.md | 2 +- src/FlaUI.WebDriver.UITests/ExecuteTests.cs | 12 ++++++++++++ .../Controllers/ExecuteController.cs | 16 +++++++++++++++- .../Services/IWindowsExtensionService.cs | 1 + .../Services/WindowsExtensionService.cs | 12 +++++++++--- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 824ee5c..63661e2 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ const result = driver.executeScript("powerShell", [{ command: `1+1` }]); ## Windows extensions -To enable easy switching from appium-windows-driver, there is a rudimentary implementation of `windows: click`, `windows: hover`, `windows: scroll`, `windows: keys`, `windows: getClipboard` and `windows: setClipboard`. +To enable easy switching from appium-windows-driver, there is a rudimentary implementation of `windows: click`, `windows: hover`, `windows: scroll`, `windows: keys`, `windows: getClipboard`, `windows: setClipboard` and `windows: clearClipboard`. ## Supported WebDriver Commands diff --git a/src/FlaUI.WebDriver.UITests/ExecuteTests.cs b/src/FlaUI.WebDriver.UITests/ExecuteTests.cs index 6380d81..8fdeb02 100644 --- a/src/FlaUI.WebDriver.UITests/ExecuteTests.cs +++ b/src/FlaUI.WebDriver.UITests/ExecuteTests.cs @@ -64,6 +64,18 @@ public void ExecuteScript_WindowsSetClipboard_IsSupported() Assert.That(element.Text, Is.EqualTo("Test TextBoxPasted!")); } + [Test] + public void ExecuteScript_WindowsClearClipboard_IsSupported() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + driver.ExecuteScript("windows: setClipboard", new Dictionary { + ["b64Content"] = "Pasted!"}); + driver.ExecuteScript("windows: clearClipboard"); + var result = driver.ExecuteScript("windows: getClipboard", new Dictionary {}); + Assert.That(result, Is.EqualTo("")); + } + [Test] public void ExecuteScript_WindowsHoverXY_IsSupported() { diff --git a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs index c6d6858..170e8cc 100644 --- a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs +++ b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs @@ -41,8 +41,11 @@ public async Task ExecuteScript([FromRoute] string sessionId, [Fro return await ExecuteWindowsSetClipboardScript(session, executeScriptRequest); case "windows: getClipboard": return await ExecuteWindowsGetClipboardScript(session, executeScriptRequest); + case "windows: clearClipboard": + return await ExecuteWindowsClearClipboardScript(session, executeScriptRequest); default: - throw WebDriverResponseException.UnsupportedOperation("Only 'powerShell', 'windows: keys', 'windows: click', 'windows: hover' scripts are supported"); + throw WebDriverResponseException.UnsupportedOperation("Only 'powerShell', 'windows: keys', 'windows: click', 'windows: hover', 'windows: scroll', " + + "'windows: setClipboard', 'windows: getClipboard', 'windows: clearClipboard' scripts are supported"); } } @@ -124,6 +127,17 @@ private async Task ExecuteWindowsGetClipboardScript(Session sessio return WebDriverResult.Success(result); } + private async Task ExecuteWindowsClearClipboardScript(Session session, ExecuteScriptRequest executeScriptRequest) + { + if (executeScriptRequest.Args.Count != 0) + { + throw WebDriverResponseException.InvalidArgument($"No arguments expected for the windows: getClipboard script, but got {executeScriptRequest.Args.Count} arguments"); + } + + await _windowsExtensionService.ExecuteClearClipboardScript(session); + return WebDriverResult.Success(); + } + private async Task ExecuteWindowsClickScript(Session session, ExecuteScriptRequest executeScriptRequest) { if (executeScriptRequest.Args.Count != 1) diff --git a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs index f2abe95..bdbae2e 100644 --- a/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/IWindowsExtensionService.cs @@ -10,5 +10,6 @@ public interface IWindowsExtensionService Task ExecuteKeyScript(Session session, WindowsKeyScript action); Task ExecuteGetClipboardScript(Session session, WindowsGetClipboardScript action); Task ExecuteSetClipboardScript(Session session, WindowsSetClipboardScript action); + Task ExecuteClearClipboardScript(Session session); } } \ No newline at end of file diff --git a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs index b3067e4..c8e1b56 100644 --- a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs @@ -17,7 +17,7 @@ public WindowsExtensionService(ILogger logger) public Task ExecuteGetClipboardScript(Session session, WindowsGetClipboardScript action) { - switch(action.ContentType) + switch (action.ContentType) { default: case "plaintext": @@ -59,6 +59,12 @@ public Task ExecuteSetClipboardScript(Session session, WindowsSetClipboardScript return Task.CompletedTask; } + public Task ExecuteClearClipboardScript(Session session) + { + ExecuteOnClipboardThread(() => System.Windows.Forms.Clipboard.Clear()); + return Task.CompletedTask; + } + private void ExecuteOnClipboardThread(System.Action action) { // See https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.clipboard?view=windowsdesktop-8.0#remarks @@ -138,7 +144,7 @@ private Point GetPoint(string? elementId, int? x, int? y, Session session) Y = element.BoundingRectangle.Top + y.Value }; } - + return element.BoundingRectangle.Center(); } @@ -146,7 +152,7 @@ private Point GetPoint(string? elementId, int? x, int? y, Session session) { return new Point { X = x.Value, Y = y.Value }; } - + throw WebDriverResponseException.InvalidArgument("Either element ID or x and y must be provided"); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy