Skip to content

Commit 5f17a59

Browse files
committed
BookLib: extend report test with print to pdf
1 parent 01368a2 commit 5f17a59

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/Samples.UITest/BookLibrary.Test/Tests/ReportingTest.cs

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using FlaUI.Core.Capturing;
1+
using FlaUI.Core.AutomationElements;
2+
using FlaUI.Core.Capturing;
23
using FlaUI.Core.Definitions;
4+
using FlaUI.Core.Tools;
5+
using UITest.SystemViews;
36
using Xunit;
47
using Xunit.Abstractions;
58

@@ -21,10 +24,30 @@ public void CreateReportTest() => Run(() =>
2124
reportView.CreateBookListReportButton.Click();
2225
Assert.True(reportView.PrintButton.IsEnabled);
2326
Capture.Screen().ToFile(GetScreenshotFile("BookListReport"));
27+
PrintAsPdf(GetScreenshotFile("BookListReport.pdf"));
2428

2529
reportView.CreateBorrowedBooksReportButton.Click();
2630
Capture.Screen().ToFile(GetScreenshotFile("BorrowedBooksReport"));
31+
PrintAsPdf(GetScreenshotFile("BorrowedBooksReport.pdf"));
2732

28-
window.Close();
33+
var dataMenu = window.DataMenu;
34+
dataMenu.Click();
35+
dataMenu.ExitMenuItem.Click();
36+
37+
38+
void PrintAsPdf(string fileName)
39+
{
40+
if (File.Exists(fileName)) File.Delete(fileName);
41+
42+
reportView.PrintButton.Click();
43+
var printDialog = PrintDialog.GetDialog(Automation);
44+
printDialog.PrinterSelector.Select(printDialog.PrintToPdf.Name);
45+
Retry.WhileFalse(() => printDialog.PrintButton.IsEnabled, throwOnTimeout: true);
46+
printDialog.PrintButton.Invoke();
47+
48+
var saveFileDialog = window.FirstModalWindow().As<SaveFileDialog>();
49+
saveFileDialog.SetFileName(fileName);
50+
saveFileDialog.SaveButton.Click();
51+
}
2952
});
3053
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using FlaUI.Core;
2+
using FlaUI.Core.AutomationElements;
3+
4+
namespace UITest.SystemViews;
5+
6+
public class PrintDialog(FrameworkAutomationElementBase element) : Window(element)
7+
{
8+
public static PrintDialog GetDialog(AutomationBase automation)
9+
{
10+
var desktop = automation.GetDesktop();
11+
return desktop.Find(x => x.ByName("Windows Print")).As<PrintDialog>();
12+
}
13+
14+
public ComboBox PrinterSelector => this.Find("printerSelector").AsComboBox();
15+
16+
public ComboBoxItem PrintToPdf => PrinterSelector.Items.First(x => x.Name == "Microsoft Print to PDF");
17+
18+
public ComboBox PageOrientationComboBox => this.Find("PageOrientation_ItemList").AsComboBox();
19+
20+
public CheckBox UseAppFeaturesCheckBox => this.Find("UseAppFeaturesCheckBox").AsCheckBox();
21+
22+
public Button PrintButton => this.Find("PrintButton").AsButton();
23+
24+
public Button CloseButton => this.Find("CloseButton").AsButton();
25+
}

0 commit comments

Comments
 (0)