Skip to content

Commit

Permalink
UITest: More robust implementation of PrintDialog.TryGetDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Feb 3, 2025
1 parent fe53c25 commit 57ab17f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Samples.UITest/UITest.Core/SystemViews/PrintDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Conditions;
using FlaUI.Core.Definitions;
using System.Diagnostics;

Expand All @@ -11,12 +12,13 @@ public class PrintDialog(FrameworkAutomationElementBase element) : Window(elemen
{
var p = Process.GetProcesses().FirstOrDefault(x => x.ProcessName.Contains("PrintDialog", StringComparison.OrdinalIgnoreCase));
if (p is null) return null;
Thread.Sleep(500);
var desktop = automation.GetDesktop();
var topLevel = desktop.FindAllChildren(x => x.ByControlType(ControlType.Window));
AutomationElement? printDialog = null;
foreach (var x in topLevel)
{
printDialog = x.FindFirstChild(x => x.ByProcessId(p.Id)); // It is a Window on the second level with process name "PrintDialog"
printDialog = x.FindFirstChild(x => new AndCondition(x.ByControlType(ControlType.Window), x.ByProcessId(p.Id))); // It is a Window on the second level with process name "PrintDialog"
if (printDialog is not null) break;
}
return printDialog?.As<PrintDialog>();
Expand Down

0 comments on commit 57ab17f

Please sign in to comment.