diff --git a/.claude/skills/fix-issue/references/verification-windows.md b/.claude/skills/fix-issue/references/verification-windows.md index e849cbf8f0..96fdeafbe8 100644 --- a/.claude/skills/fix-issue/references/verification-windows.md +++ b/.claude/skills/fix-issue/references/verification-windows.md @@ -34,7 +34,8 @@ Read this when a `verify.sh` verdict needs interpreting for the Windows app, bef - **They drive the real app through UI Automation (FlaUI)** and take the mouse and keyboard. `TABLEPRO_APP` names the published `TablePro.exe`, which the `ui` step finds under `windows/src/TablePro.App/bin/` in the `publish` folder for the SDK's runtime identifier; run `app` first. - **Each launch gets a new data folder** through `TABLEPRO_DATA_DIR`, with its theme and row limit written into `settings.json`, so the user's connections never show and nothing carries over. - **`windows/ci/desktop.ps1` is for hosted runners.** It writes a machine policy, stops system processes and changes the display mode. Never run it on a developer's machine. -- **Keys and clicks go through `AppSession`.** It brings the app to the front first, and `Chord`, `Click(element, landed)`, `Drag(..., landed)` and `TypeInto` try up to three times, waiting 5 seconds each for the app to show the input landed. A new test sends a shortcut with `Chord` and a `landed` check, never a bare `Keyboard.TypeSimultaneously`. +- **Keys and clicks go through `AppSession`.** It brings the app to the front first, and `Chord`, `Click(element, landed)`, `Drag(..., landed)` and `TypeInto` try up to three times, waiting 5 seconds each for the app to show the input landed. A new test sends a shortcut with `Chord` and a `landed` check, never a bare `Keyboard.TypeSimultaneously`. Every click reads the element's clickable point again until it has one, since a live element's point can fail to read for a moment; a test never calls FlaUI's own `Click`, `RightClick` or `DoubleClick`. +- **A list the app builds again after a change drops the row a test just found.** Read a row of such a list inside `AppSession.Holds`, which counts a gone row or its unsupported state as not yet (`windows/docs/decisions/0004-app-shell.md`, What the runner showed). - **A drag goes through `SendInput`** (`PointerInput`). FlaUI moves the pointer with `SetCursorPos`, which WinUI does not take as a pointer moving with the button down. - **UIA reads an empty Name as none.** WinUI reports an empty name as not supported, so FlaUI's `Name` throws `PropertyNotSupportedException`: it did once on x64, in run 41566360608. Read a name that can be empty through `Properties.Name.ValueOrDefault`. - **`TablePattern.ColumnHeaders` is empty on Windows App SDK 2.6.4.** `CUIATableProviderWrapper::GetColumnHeaders` releases its SAFEARRAY before filling it; microsoft/microsoft-ui-xaml#11820 fixed it after 2.6.4. Read the headers from the header peers, or a cell's `TableItem` while its header is realized (`windows/docs/decisions/0003-data-grid-control.md`, Consequences). diff --git a/windows/docs/decisions/0004-app-shell.md b/windows/docs/decisions/0004-app-shell.md index abc454350d..b9ac9bc6c0 100644 --- a/windows/docs/decisions/0004-app-shell.md +++ b/windows/docs/decisions/0004-app-shell.md @@ -209,6 +209,8 @@ Facts the CI runs on `windows-2025` and `windows-11-arm` established, which the - `TreeViewItem`'s multiple-selection check box is raw to UI Automation, so the tests check a row through its `SelectionItem` pattern, which reads that box. - A click on a `MenuFlyoutSubItem` did not always open its submenu, and FlaUI's pointer glides to the next item across its neighbours, whose own submenus then open. The tests open a submenu through `ExpandCollapse` and invoke its item. - `windows-2025` drags a window as an outline: "Show window contents while dragging" is off there (`SPI_GETDRAGFULLWINDOWS` 0), while `windows-11-arm` has it on. TabView merges a dragged tab into another strip from `InputNonClientPointerSource.WindowRectChanging`, which the outline drag raised once, on release; with window contents on, the same drag raised it 82 times and the tab merged and tore out again before the release (run 41837948701). CI turns the setting on with `Set-DragFullWindows` in `windows/ci/desktop.ps1`. +- A list the app builds again after each change (saved queries, the Connections page, history) drops every row, and a row a client found a moment before reads as gone: `UIA_E_ELEMENTNOTAVAILABLE` for its properties, and not supported for a tree row's `ExpandCollapseState`, since WinUI's `TreeViewItemDataAutomationPeer` throws once its item has no container. `AQueryIsSavedIntoAFolderAndARunIsPinned` found the folder row just before the move rebuilt the tree and read it just after, and failed in 7 of 12 rounds on `windows-11-arm` (run 43737243526). Read from the row found before the move, the old check threw `PropertyNotSupportedException` 12 times in 12, and the same check inside `AppSession.Holds`, which reads the new row on the next try, passed 12 times in 12; with it, both themes of the test passed 30 rounds in five `windows-11-arm` jobs and 6 on `windows-2025` (run 43742489353). +- A live element's clickable point can fail to read for a moment: on the Go to page button, with the same runtime id and the hit test at its center finding it, 22 of 22,231 reads over 216 page changes failed on `windows-11-arm` and 4 of 5,762 over 48 on `windows-2025`, after Go to page and after Next page alike, each between two reads that passed (runs 43737243526 and 43742489353). FlaUI's `Click` throws `NoClickablePointException` on the first failed read, which failed `ATableKeepsItsPageSizeAndGoesToAPageInsideItsCount` in runs 43690747382 and 43707549355; no flyout covered the button. `AppSession` reads the point again for up to 5 seconds before each click. ## Consequences - The core gained the library and connecting through it: `Core::library`, `connect_saved`, `test_connection`, `parse_connection_url`, `DatabaseSession::table_query` and `sorted_query` with `sql_syntax::with_order_by` and `sort_reference`, `ResultSet::sorted` over `value::order`, and `Core::with_system_secrets`, which keeps secrets in Credential Manager on Windows (`core/ARCHITECTURE.md`, Platforms). diff --git a/windows/tests/TablePro.App.UITests/AppSession.cs b/windows/tests/TablePro.App.UITests/AppSession.cs index f2b4f6e692..cf914f10b9 100644 --- a/windows/tests/TablePro.App.UITests/AppSession.cs +++ b/windows/tests/TablePro.App.UITests/AppSession.cs @@ -1,8 +1,10 @@ using System.Diagnostics; +using System.Runtime.InteropServices; using FlaUI.Core; using FlaUI.Core.AutomationElements; using FlaUI.Core.Capturing; using FlaUI.Core.Definitions; +using FlaUI.Core.Exceptions; using FlaUI.Core.Input; using FlaUI.Core.Tools; using FlaUI.Core.WindowsAPI; @@ -14,6 +16,7 @@ namespace TablePro.App.UITests; internal sealed class AppSession : IDisposable { public static readonly TimeSpan Wait = TimeSpan.FromSeconds(30); + private const int ElementNotAvailable = unchecked((int)0x80040201); private static readonly PackageTestState _packageState = new(); private readonly UIA3Automation _automation = new(); @@ -95,7 +98,7 @@ public static string LibraryFile(string folder) => public void Drag(AutomationElement from, AutomationElement to) { Front(); - Drag(from.GetClickablePoint(), to.GetClickablePoint()); + Drag(PointOf(from), PointOf(to)); } // The Arm64 runner's own windows take keys and drags now and then, so each goes again until it lands. @@ -142,7 +145,23 @@ public void DragThrough(Window window, Func start, Func landed) => - Again(() => element.RightClick(), landed, "The right-click"); + Again(() => RightClick(element), landed, "The right-click"); + + public void RightClick(AutomationElement element) + { + var point = PointOf(element); + Front(); + Mouse.RightClick(point); + FlaUI.Core.Input.Wait.UntilInputIsProcessed(); + } + + public void DoubleClick(AutomationElement element) + { + var point = PointOf(element); + Front(); + Mouse.DoubleClick(point); + FlaUI.Core.Input.Wait.UntilInputIsProcessed(); + } public void Chord(Func landed, params VirtualKeyShort[] keys) => Again(() => Keyboard.TypeSimultaneously(keys), landed, string.Join("+", keys)); @@ -245,7 +264,7 @@ public void Check(AutomationElement row, bool isChecked = true) { if (box.AsCheckBox().IsChecked != isChecked) { - box.Click(); + Click(box); } return; @@ -265,7 +284,7 @@ public void Check(AutomationElement row, bool isChecked = true) return; } - row.Click(); + Click(row); } // The ContentDialog template names its primary button PrimaryButton; a name tells it from a dialog still closing. @@ -353,19 +372,47 @@ public AutomationElement FindByName(string name, AutomationElement? scope = null public AutomationElement FindByNamePrefix(string prefix, AutomationElement scope) => Retry.WhileNull( - () => scope.FindAllDescendants().FirstOrDefault(element => - element.Properties.Name.TryGetValue(out var name) && name.StartsWith(prefix, StringComparison.Ordinal)), + () => scope.FindAllDescendants().FirstOrDefault(element => Holds(() => + element.Properties.Name.TryGetValue(out var name) && name.StartsWith(prefix, StringComparison.Ordinal))), Wait, throwOnTimeout: false).Result ?? throw Failure($"No element named {prefix}... appeared."); + // A list built again after a change drops the row just found, which WinUI then reports gone or, for a tree row's state, not supported. + public static bool Holds(Func check) + { + try + { + return check(); + } + catch (Exception exception) when (exception is PropertyNotSupportedException or ElementNotAvailableException + || exception is COMException { HResult: ElementNotAvailable }) + { + return false; + } + } + // Mouse and keys reach the foreground window, and the Arm64 runner opens windows of its own over the app. public void Front(Window? window = null) => (window ?? Window).SetForeground(); public void Click(AutomationElement element, Window? window = null) { + var point = PointOf(element); Front(window); - element.Click(); + Mouse.Click(point); + FlaUI.Core.Input.Wait.UntilInputIsProcessed(); + } + + // FlaUI's own click gives up on the first failed read, and a live element's point can fail to read for a moment. + public System.Drawing.Point PointOf(AutomationElement element) + { + var point = System.Drawing.Point.Empty; + if (!Retry.WhileFalse(() => element.TryGetClickablePoint(out point), TimeSpan.FromSeconds(5), throwOnTimeout: false).Success) + { + throw Failure("The element to click has no clickable point.", screen: true); + } + + return point; } // A window the runner opens for a moment can take a click, so it goes again until the app shows it landed. diff --git a/windows/tests/TablePro.App.UITests/BrowseObjectsTests.cs b/windows/tests/TablePro.App.UITests/BrowseObjectsTests.cs index cff5de37fe..9e639ee9bc 100644 --- a/windows/tests/TablePro.App.UITests/BrowseObjectsTests.cs +++ b/windows/tests/TablePro.App.UITests/BrowseObjectsTests.cs @@ -92,8 +92,7 @@ private static void OpenAgain(AppSession app, AutomationElement run, string tab) { for (var attempt = 0; attempt < 3; attempt++) { - app.Front(); - run.DoubleClick(); + app.DoubleClick(run); if (Retry.WhileNull( () => app.Window.FindFirstDescendant(condition => condition.ByAutomationId("SqlEditor").And(condition.ByName($"SQL editor, {tab}"))), diff --git a/windows/tests/TablePro.App.UITests/ConnectionSecurityTests.cs b/windows/tests/TablePro.App.UITests/ConnectionSecurityTests.cs index 88b1a46cbc..08fb940c0d 100644 --- a/windows/tests/TablePro.App.UITests/ConnectionSecurityTests.cs +++ b/windows/tests/TablePro.App.UITests/ConnectionSecurityTests.cs @@ -36,9 +36,7 @@ public void SqlServerStrictAndWindowsAuthenticationAreSavedAndRestored(string th app.Find("SaveButton", form).AsButton().Invoke(); app.WaitForClose("New connection"); - var row = app.FindByNamePrefix("Strict SQL Server,", app.Find("ConnectionTree")); - app.Front(); - row.RightClick(); + app.RightClick(app.FindByNamePrefix("Strict SQL Server,", app.Find("ConnectionTree"))); app.FindMenuItem("Edit...").Patterns.Invoke.Pattern.Invoke(); var edit = app.WaitForWindow("Edit connection"); Assert.Equal("Windows authentication", app.Find("AuthBox", edit).AsComboBox().SelectedItem?.Text); diff --git a/windows/tests/TablePro.App.UITests/SavedQueriesTests.cs b/windows/tests/TablePro.App.UITests/SavedQueriesTests.cs index c22cc939ef..4f8e29cf5a 100644 --- a/windows/tests/TablePro.App.UITests/SavedQueriesTests.cs +++ b/windows/tests/TablePro.App.UITests/SavedQueriesTests.cs @@ -61,7 +61,8 @@ public void AQueryIsSavedIntoAFolderAndARunIsPinned(string theme) bool Shown() => tree.FindFirstDescendant(condition => condition.ByName($"Five tracks, {FiveTracks}")) is { IsOffscreen: false }; Assert.True(Retry.WhileFalse( - () => Folder().Patterns.ExpandCollapse.Pattern.ExpandCollapseState.Value == ExpandCollapseState.Expanded && Shown(), + () => AppSession.Holds(() => + Folder().Patterns.ExpandCollapse.Pattern.ExpandCollapseState.Value == ExpandCollapseState.Expanded && Shown()), AppSession.Wait, throwOnTimeout: false).Success); app.Screenshot("72-saved-query-folders"); @@ -81,13 +82,13 @@ bool Shown() => tree.FindFirstDescendant(condition => app.RightClick(app.FindByNamePrefix(FiveTracks, runs), () => app.TryFindMenuItem("Pin") is not null); app.FindMenuItem("Pin").Patterns.Invoke.Pattern.Invoke(); var pinned = Retry.WhileFalse( - () => app.FindByNamePrefix(FiveTracks, runs).Name.EndsWith(", Pinned", StringComparison.Ordinal), + () => AppSession.Holds(() => app.FindByNamePrefix(FiveTracks, runs).Name.EndsWith(", Pinned", StringComparison.Ordinal)), AppSession.Wait, throwOnTimeout: false).Success; Assert.True(pinned, app.FindByNamePrefix(FiveTracks, runs).Name); // The list is built again with the pinned run first, and UI Automation lists a row before it is drawn. Assert.True(Retry.WhileFalse( - () => app.FindByNamePrefix(FiveTracks, runs) is { IsOffscreen: false } row && row.BoundingRectangle.Height > 0, + () => AppSession.Holds(() => app.FindByNamePrefix(FiveTracks, runs) is { IsOffscreen: false } row && row.BoundingRectangle.Height > 0), AppSession.Wait, throwOnTimeout: false).Success); Thread.Sleep(1_000); @@ -95,8 +96,8 @@ bool Shown() => tree.FindFirstDescendant(condition => app.RightClick(app.FindByNamePrefix(FiveTracks, runs), () => app.TryFindMenuItem("Unpin") is not null); app.FindMenuItem("Unpin").Patterns.Invoke.Pattern.Invoke(); - Assert.True(Retry.WhileTrue( - () => app.FindByNamePrefix(FiveTracks, runs).Name.EndsWith(", Pinned", StringComparison.Ordinal), + Assert.True(Retry.WhileFalse( + () => AppSession.Holds(() => !app.FindByNamePrefix(FiveTracks, runs).Name.EndsWith(", Pinned", StringComparison.Ordinal)), AppSession.Wait, throwOnTimeout: false).Success); } @@ -106,8 +107,7 @@ private static void InsertSaved(AppSession app, Func row, str { for (var attempt = 0; attempt < 3; attempt++) { - app.Front(); - row().DoubleClick(); + app.DoubleClick(row()); if (Retry.WhileFalse( () => AppSession.EditorText(app.FindEditor(tab)).TrimEnd('\r', '\n').Length > 0, TimeSpan.FromSeconds(5), diff --git a/windows/tests/TablePro.App.UITests/ShellPolishTests.cs b/windows/tests/TablePro.App.UITests/ShellPolishTests.cs index 30d5939932..94c52631da 100644 --- a/windows/tests/TablePro.App.UITests/ShellPolishTests.cs +++ b/windows/tests/TablePro.App.UITests/ShellPolishTests.cs @@ -178,9 +178,7 @@ public void APasswordIsAskedForWhenNoneIsSaved(string theme) // The form saved the empty password it was given; taking it away leaves the connection with none saved. var target = $"TablePro/connection/{ConnectionId(app.DataFolder)}/database-password"; Credentials.Delete(target); - var row = app.FindByNamePrefix("Asks,", app.Find("ConnectionTree")); - app.Front(); - row.DoubleClick(); + app.DoubleClick(app.FindByNamePrefix("Asks,", app.Find("ConnectionTree"))); var box = app.Find("SecretBox"); app.Screenshot("18-password-asked"); @@ -367,13 +365,12 @@ public void TheConnectionsPageRenamesTagsDropsAndSelects(string theme) app.Chord(() => app.TryFind("RenameBox") is null, VirtualKeyShort.RETURN); var music = app.FindByNamePrefix("Music,", tree); - app.Front(); - music.RightClick(); + app.RightClick(music); app.OpenSubmenu("Tags", "New tag...").Patterns.Invoke.Pattern.Invoke(); app.Find("NameDialogBox").AsTextBox().Text = "demo"; app.PressDialogButton(); var tagged = Retry.WhileFalse( - () => app.FindByNamePrefix("Music,", tree).Name.EndsWith("demo", StringComparison.Ordinal), + () => AppSession.Holds(() => app.FindByNamePrefix("Music,", tree).Name.EndsWith("demo", StringComparison.Ordinal)), AppSession.Wait, throwOnTimeout: false).Success; Assert.True(tagged, app.FindByNamePrefix("Music,", tree).Name); diff --git a/windows/tests/TablePro.App.UITests/WorkspaceDailyUseTests.cs b/windows/tests/TablePro.App.UITests/WorkspaceDailyUseTests.cs index e917cfcad5..5bf61be494 100644 --- a/windows/tests/TablePro.App.UITests/WorkspaceDailyUseTests.cs +++ b/windows/tests/TablePro.App.UITests/WorkspaceDailyUseTests.cs @@ -57,15 +57,14 @@ public void AConnectionsColourAndTagsMarkItsWindow(string theme) app.Find("HomeItem").AsListBoxItem().Select(); var tree = app.Find("ConnectionTree"); - app.Front(); - app.FindByNamePrefix("Orders,", tree).RightClick(); + app.RightClick(app.FindByNamePrefix("Orders,", tree)); app.OpenSubmenu("Tags", "New tag...").Patterns.Invoke.Pattern.Invoke(); app.Find("NameDialogBox").AsTextBox().Text = "production"; app.PressDialogButton(); - Retry.WhileFalse( - () => app.FindByNamePrefix("Orders,", tree).Name.EndsWith("production", StringComparison.Ordinal), + Assert.True(Retry.WhileFalse( + () => AppSession.Holds(() => app.FindByNamePrefix("Orders,", tree).Name.EndsWith("production", StringComparison.Ordinal)), AppSession.Wait, - throwOnTimeout: false); + throwOnTimeout: false).Success); app.Find("Rail_Orders").AsListBoxItem().Select(); app.FindByName("Album", app.Find("ObjectTree"));