From 29d4b4cabbbe060692e280b206ef654b716e2ffd Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 7 May 2024 17:49:21 +0200 Subject: [PATCH 1/4] Make WebDriver DPI-aware. --- src/FlaUI.WebDriver/FlaUI.WebDriver.csproj | 1 + src/FlaUI.WebDriver/app.manifest | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 src/FlaUI.WebDriver/app.manifest diff --git a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj index 6d93b78..ae81853 100644 --- a/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj +++ b/src/FlaUI.WebDriver/FlaUI.WebDriver.csproj @@ -9,6 +9,7 @@ win-x64 true true + app.manifest diff --git a/src/FlaUI.WebDriver/app.manifest b/src/FlaUI.WebDriver/app.manifest new file mode 100644 index 0000000..c7239fd --- /dev/null +++ b/src/FlaUI.WebDriver/app.manifest @@ -0,0 +1,9 @@ + + + + + true + PerMonitorV2 + + + \ No newline at end of file From d7bb9ee5d2bbec15ed86c5c7529a9ded0cd31fd4 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 7 May 2024 17:49:52 +0200 Subject: [PATCH 2/4] Make test application DPI-aware. And expose current DPI scaling factor in status bar. --- src/TestApplications/WpfApplication/MainWindow.xaml | 4 +++- src/TestApplications/WpfApplication/MainWindow.xaml.cs | 7 +++++++ .../WpfApplication/WpfApplication.csproj | 5 +++-- src/TestApplications/WpfApplication/app.manifest | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/TestApplications/WpfApplication/app.manifest diff --git a/src/TestApplications/WpfApplication/MainWindow.xaml b/src/TestApplications/WpfApplication/MainWindow.xaml index d68aa6a..0e2cc41 100644 --- a/src/TestApplications/WpfApplication/MainWindow.xaml +++ b/src/TestApplications/WpfApplication/MainWindow.xaml @@ -32,7 +32,9 @@ - + + + diff --git a/src/TestApplications/WpfApplication/MainWindow.xaml.cs b/src/TestApplications/WpfApplication/MainWindow.xaml.cs index 1cc3b3f..bef0dbe 100644 --- a/src/TestApplications/WpfApplication/MainWindow.xaml.cs +++ b/src/TestApplications/WpfApplication/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using System.Windows.Media; namespace WpfApplication { @@ -27,6 +28,12 @@ private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArg } } + protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) + { + DpiScaling.Text = VisualTreeHelper.GetDpi(this).DpiScaleX.ToString(); + base.OnRenderSizeChanged(sizeInfo); + } + private void OnShowLabel(object sender, RoutedEventArgs e) { MenuItem menuitem = sender as MenuItem; diff --git a/src/TestApplications/WpfApplication/WpfApplication.csproj b/src/TestApplications/WpfApplication/WpfApplication.csproj index 67cb170..631b69d 100644 --- a/src/TestApplications/WpfApplication/WpfApplication.csproj +++ b/src/TestApplications/WpfApplication/WpfApplication.csproj @@ -1,4 +1,4 @@ - + WinExe @@ -6,7 +6,8 @@ disable enable true - false + false + app.manifest diff --git a/src/TestApplications/WpfApplication/app.manifest b/src/TestApplications/WpfApplication/app.manifest new file mode 100644 index 0000000..c7239fd --- /dev/null +++ b/src/TestApplications/WpfApplication/app.manifest @@ -0,0 +1,9 @@ + + + + + true + PerMonitorV2 + + + \ No newline at end of file From 3dc078e1981b87b3422f9de6ed15cdebda71edf9 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 7 May 2024 17:50:02 +0200 Subject: [PATCH 3/4] Account for DPI scaling in tests. --- src/FlaUI.WebDriver.UITests/ElementTests.cs | 9 +++++---- src/FlaUI.WebDriver.UITests/WindowTests.cs | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/ElementTests.cs b/src/FlaUI.WebDriver.UITests/ElementTests.cs index aad7bc8..6be2ada 100644 --- a/src/FlaUI.WebDriver.UITests/ElementTests.cs +++ b/src/FlaUI.WebDriver.UITests/ElementTests.cs @@ -168,14 +168,15 @@ public void GetElementRect_Default_IsSupported() using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); var element = driver.FindElement(ExtendedBy.AccessibilityId("EditableCombo")); + var scaling = double.Parse(driver.FindElement(ExtendedBy.AccessibilityId("DpiScaling")).Text.ToString()); var location = element.Location; var size = element.Size; var windowLocation = driver.Manage().Window.Position; - Assert.That(location.X, Is.InRange(windowLocation.X + 253, windowLocation.X + 257)); - Assert.That(location.Y, Is.InRange(windowLocation.Y + 132, windowLocation.Y + 136)); - Assert.That(size.Width, Is.EqualTo(120)); - Assert.That(size.Height, Is.EqualTo(22)); + Assert.That(location.X, Is.InRange(windowLocation.X + (253 * scaling), windowLocation.X + (257 * scaling))); + Assert.That(location.Y, Is.InRange(windowLocation.Y + (132 * scaling), windowLocation.Y + (136 * scaling))); + Assert.That(size.Width, Is.EqualTo(120 * scaling)); + Assert.That(size.Height, Is.EqualTo(22 * scaling)); } [TestCase("TextBox")] diff --git a/src/FlaUI.WebDriver.UITests/WindowTests.cs b/src/FlaUI.WebDriver.UITests/WindowTests.cs index ee803fb..8735fe9 100644 --- a/src/FlaUI.WebDriver.UITests/WindowTests.cs +++ b/src/FlaUI.WebDriver.UITests/WindowTests.cs @@ -15,13 +15,14 @@ public void GetWindowRect_Default_IsSupported() var driverOptions = FlaUIDriverOptions.TestApp(); using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + var scaling = double.Parse(driver.FindElement(ExtendedBy.AccessibilityId("DpiScaling")).Text.ToString()); var position = driver.Manage().Window.Position; var size = driver.Manage().Window.Size; Assert.That(position.X, Is.GreaterThanOrEqualTo(0)); Assert.That(position.Y, Is.GreaterThanOrEqualTo(0)); - Assert.That(size.Width, Is.InRange(629, 630)); - Assert.That(size.Height, Is.InRange(515, 516)); + Assert.That(size.Width, Is.InRange(629 * scaling, 630 * scaling)); + Assert.That(size.Height, Is.InRange(515 * scaling, 516 * scaling)); } [Test] From c0f876fe7353a635c6b638dd69589c1e6f57587e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 8 May 2024 15:09:57 +0200 Subject: [PATCH 4/4] Extract getting scaling to separate method. --- src/FlaUI.WebDriver.UITests/ElementTests.cs | 2 +- src/FlaUI.WebDriver.UITests/TestUtil/TestApplication.cs | 6 ++++++ src/FlaUI.WebDriver.UITests/WindowTests.cs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/FlaUI.WebDriver.UITests/ElementTests.cs b/src/FlaUI.WebDriver.UITests/ElementTests.cs index 6be2ada..095a73a 100644 --- a/src/FlaUI.WebDriver.UITests/ElementTests.cs +++ b/src/FlaUI.WebDriver.UITests/ElementTests.cs @@ -168,7 +168,7 @@ public void GetElementRect_Default_IsSupported() using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); var element = driver.FindElement(ExtendedBy.AccessibilityId("EditableCombo")); - var scaling = double.Parse(driver.FindElement(ExtendedBy.AccessibilityId("DpiScaling")).Text.ToString()); + var scaling = TestApplication.GetScaling(driver); var location = element.Location; var size = element.Size; diff --git a/src/FlaUI.WebDriver.UITests/TestUtil/TestApplication.cs b/src/FlaUI.WebDriver.UITests/TestUtil/TestApplication.cs index 081f5b9..9c4cbfd 100644 --- a/src/FlaUI.WebDriver.UITests/TestUtil/TestApplication.cs +++ b/src/FlaUI.WebDriver.UITests/TestUtil/TestApplication.cs @@ -1,5 +1,6 @@ using System.IO; using System.Linq; +using OpenQA.Selenium.Remote; namespace FlaUI.WebDriver.UITests.TestUtil { @@ -9,6 +10,11 @@ public static class TestApplication private static readonly string s_currentDirectory = Directory.GetCurrentDirectory(); private static readonly string s_solutionDirectory = FindSolutionDirectory(s_currentDirectory); + public static double GetScaling(RemoteWebDriver driver) + { + return double.Parse(driver.FindElement(ExtendedBy.AccessibilityId("DpiScaling")).Text.ToString()); + } + private static string FindSolutionDirectory(string currentDirectory) { while (!Directory.GetFiles(currentDirectory, "*.sln").Any()) diff --git a/src/FlaUI.WebDriver.UITests/WindowTests.cs b/src/FlaUI.WebDriver.UITests/WindowTests.cs index 8735fe9..ff80c99 100644 --- a/src/FlaUI.WebDriver.UITests/WindowTests.cs +++ b/src/FlaUI.WebDriver.UITests/WindowTests.cs @@ -15,7 +15,7 @@ public void GetWindowRect_Default_IsSupported() var driverOptions = FlaUIDriverOptions.TestApp(); using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); - var scaling = double.Parse(driver.FindElement(ExtendedBy.AccessibilityId("DpiScaling")).Text.ToString()); + var scaling = TestApplication.GetScaling(driver); var position = driver.Manage().Window.Position; var size = driver.Manage().Window.Size;