Skip to content

Commit d66dd9f

Browse files
committed
test(dialoghost): stabilize focus tests by using Wait.For
Replace fixed Task.Delay calls with polling assertions to improve test reliability during focus transitions. Fixes #4027
1 parent e899da1 commit d66dd9f

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

tests/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using static MaterialDesignThemes.UITests.MaterialDesignSpec;
66

7-
87
namespace MaterialDesignThemes.UITests.WPF.DialogHosts;
98

109
public class DialogHostTests : TestBase
@@ -556,20 +555,16 @@ public async Task DialogHost_TrapsFocusInsidePopup_WhenTabbing(string dialogHost
556555

557556
await openDialogButton.LeftClick();
558557

559-
await Task.Delay(400, TestContext.Current!.CancellationToken);
560-
561558
// By default the first focusable element should be focused
562-
await Assert.That(await textBoxOne.GetIsFocused()).IsTrue();
559+
await Wait.For(async () => await Assert.That(await textBoxOne.GetIsFocused()).IsTrue());
563560

564561
await textBoxOne.SendInput(new KeyboardInput(inputActions));
565-
await Task.Delay(100, TestContext.Current!.CancellationToken);
566-
567-
await Assert.That(await textBoxTwo.GetIsFocused()).IsTrue();
562+
563+
await Wait.For(async () => await Assert.That(await textBoxTwo.GetIsFocused()).IsTrue());
568564

569565
await textBoxTwo.SendInput(new KeyboardInput(inputActions));
570-
await Task.Delay(100, TestContext.Current!.CancellationToken);
571566

572-
await Assert.That(await textBoxOne.GetIsFocused()).IsTrue();
567+
await Wait.For(async () => await Assert.That(await textBoxOne.GetIsFocused()).IsTrue());
573568

574569
recorder.Success();
575570

0 commit comments

Comments
 (0)