diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bc18f00..08b8e55 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,6 @@ version: 2 updates: - package-ecosystem: "nuget" - directory: "/" + directory: "/src" schedule: interval: "daily" diff --git a/src/FlaUI.WebDriver.UITests/ActionsTest.cs b/src/FlaUI.WebDriver.UITests/ActionsTests.cs similarity index 100% rename from src/FlaUI.WebDriver.UITests/ActionsTest.cs rename to src/FlaUI.WebDriver.UITests/ActionsTests.cs diff --git a/src/FlaUI.WebDriver.UITests/ElementTests.cs b/src/FlaUI.WebDriver.UITests/ElementTests.cs index a658ee4..7c38ff8 100644 --- a/src/FlaUI.WebDriver.UITests/ElementTests.cs +++ b/src/FlaUI.WebDriver.UITests/ElementTests.cs @@ -300,6 +300,18 @@ public void GetAttribute_TextBox_ReturnsValue(string attributeName, string expec Assert.That(value, Is.EqualTo(expectedValue)); } + [Test] + public void GetAttribute_DesktopElement_ReturnsAttribute() + { + var driverOptions = FlaUIDriverOptions.RootApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + var element = driver.FindElement(By.Name("Taskbar")); + + var result = element.GetDomAttribute("ClassName"); + + Assert.That(result, Is.EqualTo("Shell_TrayWnd")); + } + [Test] public void GetAttribute_PatternProperty_ReturnsValue() { diff --git a/src/FlaUI.WebDriver.UITests/FindElementsTests.cs b/src/FlaUI.WebDriver.UITests/FindElementsTests.cs index 4ef3ca6..93341dc 100644 --- a/src/FlaUI.WebDriver.UITests/FindElementsTests.cs +++ b/src/FlaUI.WebDriver.UITests/FindElementsTests.cs @@ -9,7 +9,7 @@ namespace FlaUI.WebDriver.UITests public class FindElementsTests { [Test] - public void FindElement_FromRoot_ReturnsElement() + public void FindElement_FromDesktop_ReturnsElement() { var driverOptions = FlaUIDriverOptions.RootApp(); using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); diff --git a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj index a27aeb0..3ac7a98 100644 --- a/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj +++ b/src/FlaUI.WebDriver.UITests/FlaUI.WebDriver.UITests.csproj @@ -8,10 +8,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/FlaUI.WebDriver.UITests/ScreenshotTests.cs b/src/FlaUI.WebDriver.UITests/ScreenshotTests.cs new file mode 100644 index 0000000..1754a62 --- /dev/null +++ b/src/FlaUI.WebDriver.UITests/ScreenshotTests.cs @@ -0,0 +1,36 @@ +using FlaUI.WebDriver.UITests.TestUtil; +using NUnit.Framework; +using OpenQA.Selenium.Remote; +using System.Drawing; +using System.IO; + +namespace FlaUI.WebDriver.UITests +{ + public class ScreenshotTests + { + [Test] + public void GetScreenshot_FromDesktop_ReturnsScreenshot() + { + var driverOptions = FlaUIDriverOptions.RootApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + + var screenshot = driver.GetScreenshot(); + + Assert.That(screenshot.AsByteArray.Length, Is.Not.Zero); + } + + [Test] + public void GetScreenshot_FromApplication_ReturnsScreenshotOfCurrentWindow() + { + var driverOptions = FlaUIDriverOptions.TestApp(); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + + var screenshot = driver.GetScreenshot(); + + Assert.That(screenshot.AsByteArray.Length, Is.Not.Zero); + using var stream = new MemoryStream(screenshot.AsByteArray); + using var image = new Bitmap(stream); + Assert.That(image.Size, Is.EqualTo(driver.Manage().Window.Size)); + } + } +} diff --git a/src/FlaUI.WebDriver/Controllers/ElementController.cs b/src/FlaUI.WebDriver/Controllers/ElementController.cs index 624a73b..12f4bff 100644 --- a/src/FlaUI.WebDriver/Controllers/ElementController.cs +++ b/src/FlaUI.WebDriver/Controllers/ElementController.cs @@ -298,7 +298,7 @@ private AutomationElement GetElement(Session session, string elementId) private Session GetActiveSession(string sessionId) { var session = GetSession(sessionId); - if (session.App == null || session.App.HasExited) + if (session.App != null && session.App.HasExited) { throw WebDriverResponseException.NoWindowsOpenForSession(); } diff --git a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs index 77eae66..6a45bc3 100644 --- a/src/FlaUI.WebDriver/Controllers/ExecuteController.cs +++ b/src/FlaUI.WebDriver/Controllers/ExecuteController.cs @@ -1,11 +1,7 @@ -using FlaUI.Core.Input; -using FlaUI.Core.WindowsAPI; -using FlaUI.WebDriver.Models; +using FlaUI.WebDriver.Models; using FlaUI.WebDriver.Services; -using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; -using System.Drawing; using System.Text.Json; namespace FlaUI.WebDriver.Controllers diff --git a/src/FlaUI.WebDriver/Controllers/ScreenshotController.cs b/src/FlaUI.WebDriver/Controllers/ScreenshotController.cs index 881c2fc..e7b51c8 100644 --- a/src/FlaUI.WebDriver/Controllers/ScreenshotController.cs +++ b/src/FlaUI.WebDriver/Controllers/ScreenshotController.cs @@ -21,9 +21,19 @@ public ScreenshotController(ILogger logger, ISessionReposi public async Task TakeScreenshot([FromRoute] string sessionId) { var session = GetActiveSession(sessionId); - var currentWindow = session.CurrentWindow; - _logger.LogInformation("Taking screenshot of window with title {WindowTitle} (session {SessionId})", currentWindow.Title, session.SessionId); - using var bitmap = currentWindow.Capture(); + AutomationElement screenshotElement; + if (session.App == null) + { + _logger.LogInformation("Taking screenshot of desktop (session {SessionId})", session.SessionId); + screenshotElement = session.Automation.GetDesktop(); + } + else + { + var currentWindow = session.CurrentWindow; + _logger.LogInformation("Taking screenshot of window with title {WindowTitle} (session {SessionId})", currentWindow.Title, session.SessionId); + screenshotElement = currentWindow; + } + using var bitmap = screenshotElement.Capture(); return await Task.FromResult(WebDriverResult.Success(GetBase64Data(bitmap))); } @@ -57,7 +67,7 @@ private AutomationElement GetElement(Session session, string elementId) private Session GetActiveSession(string sessionId) { var session = GetSession(sessionId); - if (session.App == null || session.App.HasExited) + if (session.App != null && session.App.HasExited) { throw WebDriverResponseException.NoWindowsOpenForSession(); } diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index b8a79f6..2a841ff 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -18,7 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs index d774ac1..ee25b0f 100644 --- a/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs +++ b/src/FlaUI.WebDriver/Services/WindowsExtensionService.cs @@ -2,7 +2,6 @@ using FlaUI.Core.WindowsAPI; using FlaUI.WebDriver.Models; using System.Drawing; -using System.Runtime.CompilerServices; namespace FlaUI.WebDriver.Services { @@ -25,10 +24,12 @@ public async Task ExecuteClickScript(Session session, WindowsClickScript action) { throw WebDriverResponseException.ElementNotFound(action.ElementId); } + _logger.LogDebug("Clicking element {ElementId} with mouse button {MouseButton}", action.ElementId, mouseButton); Mouse.Click(element.BoundingRectangle.Location, mouseButton); } else if (action.X.HasValue && action.Y.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); } else @@ -42,6 +43,7 @@ public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) { if (action.StartX.HasValue && action.StartY.HasValue) { + _logger.LogDebug("Moving mouse to ({X}, {Y})", action.StartX.Value, action.StartY.Value); Mouse.MoveTo(action.StartX.Value, action.StartY.Value); } else if (action.StartElementId != null) @@ -51,6 +53,7 @@ public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) { throw WebDriverResponseException.ElementNotFound(action.StartElementId); } + _logger.LogDebug("Moving mouse to element {ElementId}", action.StartElementId); Mouse.MoveTo(element.BoundingRectangle.Location); } else @@ -60,11 +63,13 @@ public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) if (action.DurationMs.HasValue) { + _logger.LogDebug("Waiting for {DurationMs}ms", action.DurationMs.Value); await Task.Delay(action.DurationMs.Value); } if (action.EndX.HasValue && action.EndY.HasValue) { + _logger.LogDebug("Moving mouse to ({X}, {Y})", action.EndX.Value, action.EndY.Value); Mouse.MoveTo(action.EndX.Value, action.EndY.Value); } else if (action.EndElementId != null) @@ -74,6 +79,7 @@ public async Task ExecuteHoverScript(Session session, WindowsHoverScript action) { throw WebDriverResponseException.ElementNotFound(action.EndElementId); } + _logger.LogDebug("Moving mouse to element {ElementId}", action.EndElementId); Mouse.MoveTo(element.BoundingRectangle.Location); } else 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