Skip to content

Commit 9130673

Browse files
author
RandomCrocodile
committed
test: fix flaky GUI protect test — deterministic tab navigation (#64)
Gui_ProtectSampleApp_ShowsSuccess intermittently failed at the Protect! button lookup (~1 in 3 runs). Two root causes: 1. ByText("Protect!") ambiguously matched both the tab header and the Protect! button (they share the caption), so the wrong element could be clicked and the tab never actually got selected. 2. WPF virtualizes inactive tab content — the Protect! button does not enter the UIA tree until the tab is selected AND rendered. The 5s button-find timeout was too short under load. Fix: match the tab by TabItem control type + name, Select() it and wait for IsSelected, then find the button with a 15s timeout. 5/5 consecutive full-suite runs now pass 3/3 (previously ~1/3 failed).
1 parent d67f926 commit 9130673

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

Tests/Confuser.GUI.Test/GuiSmokeTest.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,28 @@ public void Gui_ProtectSampleApp_ShowsSuccess() {
150150
LaunchGui($"\"{crprojPath}\"");
151151
var mainWindow = WaitForMainWindow(app);
152152

153-
// Navigate to the Protect! tab
153+
// Navigate to the Protect! tab. Match by TabItem control type + name —
154+
// NOT ByText, which ambiguously matches both the tab header and the
155+
// Protect! button (they share the caption "Protect!").
154156
var protectTab = Retry.WhileNull(
155-
() => mainWindow.FindFirstDescendant(cf => cf.ByText("Protect!")),
156-
TimeSpan.FromSeconds(5),
157-
TimeSpan.FromMilliseconds(500)).Result;
157+
() => mainWindow.FindFirstDescendant(cf =>
158+
cf.ByControlType(FlaUI.Core.Definitions.ControlType.TabItem)
159+
.And(cf.ByName("Protect!"))),
160+
TimeSpan.FromSeconds(10),
161+
TimeSpan.FromMilliseconds(300)).Result;
158162
Assert.NotNull(protectTab);
159-
protectTab.Click();
160163

161-
// Find and click the Protect! button
164+
// Select the tab and wait until it is actually selected. WPF virtualizes
165+
// inactive tab content, so the Protect! button does not enter the UIA tree
166+
// until the tab is selected and its content has rendered.
167+
var tabItem = protectTab.AsTabItem();
168+
tabItem.Select();
169+
Retry.WhileFalse(
170+
() => tabItem.IsSelected,
171+
TimeSpan.FromSeconds(5),
172+
TimeSpan.FromMilliseconds(200));
173+
174+
// Find and click the Protect! button (only present once the tab is rendered).
162175
var protectButton = Retry.WhileNull(
163176
() => {
164177
var buttons = mainWindow.FindAllDescendants(cf => cf.ByControlType(FlaUI.Core.Definitions.ControlType.Button));
@@ -167,8 +180,8 @@ public void Gui_ProtectSampleApp_ShowsSuccess() {
167180
}
168181
return null;
169182
},
170-
TimeSpan.FromSeconds(5),
171-
TimeSpan.FromMilliseconds(500)).Result;
183+
TimeSpan.FromSeconds(15),
184+
TimeSpan.FromMilliseconds(300)).Result;
172185

173186
Assert.NotNull(protectButton);
174187
output.WriteLine("Clicking Protect! button...");

0 commit comments

Comments
 (0)