Skip to content

Commit b0cfc4c

Browse files
authored
UI test screenshot capture (#40)
* UITest support screenshot capture * UITest: Action should upload test results also when test run failed * Build: Don't run NewsReader.CI.yml when System.Waf.CI.yml is changed
1 parent 8d5917c commit b0cfc4c

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

.github/workflows/NewsReader.CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- 'src/*'
77
- 'src/NewsReader/**'
88
- '.github/workflows/**'
9+
- '!.github/workflows/System.Waf.CI.yml'
910

1011
jobs:
1112
GetVersion:

.github/workflows/System.Waf.CI.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ jobs:
1919
run: dotnet build ./src/System.Waf/System.Waf.sln -c Release -p:ContinuousIntegrationBuild=true
2020
- name: Test
2121
run: dotnet test ./src/System.Waf/System.Waf.sln -c Release --no-build
22-
- name: Upload NuGet packages
22+
- name: Upload NuGet Packages
2323
uses: actions/upload-artifact@v4
2424
with:
25-
name: packages
25+
name: Packages
2626
if-no-files-found: error
2727
path: |
2828
src/System.Waf/System.Waf/**/*.nupkg
2929
src/System.Waf/System.Waf/**/*.snupkg
3030
3131
- name: UI Test
3232
run: dotnet test ./src/Samples.UITest/Samples.UITest.sln --logger "console;verbosity=detailed"
33+
- name: Upload UI Test results
34+
uses: actions/upload-artifact@v4
35+
if: always()
36+
with:
37+
name: UITestResults
38+
if-no-files-found: ignore
39+
path: |
40+
out/Samples.UITest/
41+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
[Bb]in/
1717
[Oo]bj/
1818
[Aa]pp[Pp]ackages/
19+
[Oo]ut/
1920

2021
# Unit test results
2122
[Tt]est[Rr]esults

src/Samples.UITest/Writer.Test/Tests/WriterTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FlaUI.Core.AutomationElements;
2+
using FlaUI.Core.Capturing;
23
using FlaUI.Core.Definitions;
34
using FlaUI.Core.Tools;
45
using UITest.Writer.Views;
@@ -56,7 +57,7 @@ public void NewZoomWritePrintPreviewExitWithoutSave()
5657
var fileRibbonMenu = window.FileRibbonMenu;
5758
fileRibbonMenu.MenuButton.Click();
5859
fileRibbonMenu.PrintPreviewMenuItem.Invoke();
59-
60+
6061
var printPreviewTab = window.PrintPreviewTab;
6162
Assert.True(printPreviewTab.IsSelected);
6263
printPreviewTab.ZoomOutButton.Click();
@@ -109,7 +110,9 @@ public void NewSaveRestartOpenChangeAskToSave()
109110
Log.WriteLine(saveFileDialog.GetTree());
110111
Log.WriteLine("---------");
111112
var fileName = GetTempFileName("rtf");
112-
saveFileDialog.FileName.EditableText = fileName;
113+
saveFileDialog.FileNameBox.EditableText = fileName;
114+
Capture.Screen().ToFile(GetScreenshotFile("FullSaveScreen.png"));
115+
saveFileDialog.CaptureToFile(GetScreenshotFile("SaveFileDialog.png"));
113116
saveFileDialog.SaveButton.Click();
114117

115118
fileRibbonMenu.MenuButton.Click();

src/Samples.UITest/Writer.Test/UITest.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ namespace UITest.Writer;
1414

1515
public class UITest : IDisposable
1616
{
17+
private readonly string outPath;
1718
private readonly string executable;
19+
private readonly string testOutPath;
1820
private readonly List<string> usedFiles = [];
1921
private Application? app;
20-
22+
2123
static UITest()
2224
{
2325
Mouse.MovePixelsPerMillisecond = 2;
@@ -29,14 +31,17 @@ public UITest(ITestOutputHelper log)
2931
{
3032
Log = log;
3133
var assemblyPath = Assembly.GetAssembly(typeof(UITest))!.Location;
32-
executable = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../out/Writer/Release/net8.0-windows/writer.exe"));
33-
34+
outPath = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../out/"));
35+
executable = Path.Combine(outPath, "Writer/Release/net8.0-windows/writer.exe");
36+
testOutPath = Path.Combine(outPath, "Samples.UITest/Writer/");
37+
Directory.CreateDirectory(testOutPath);
3438
Log.WriteLine($"OSVersion: {Environment.OSVersion}");
3539
Log.WriteLine($"ProcessorCount: {Environment.ProcessorCount}");
3640
Log.WriteLine($"MachineName: {Environment.MachineName}");
3741
Log.WriteLine($"UserInteractive: {Environment.UserInteractive}");
3842
Log.WriteLine($"AssemblyPath: {assemblyPath}");
3943
Log.WriteLine($"Executable: {executable}");
44+
Log.WriteLine($"TestOutPath: {testOutPath}");
4045
Automation = new()
4146
{
4247
ConnectionTimeout = TimeSpan.FromSeconds(5)
@@ -67,6 +72,8 @@ public string GetTempFileName(string fileExtension)
6772
return file;
6873
}
6974

75+
public string GetScreenshotFile(string fileName) => Path.Combine(testOutPath, fileName);
76+
7077
public void Dispose()
7178
{
7279
if (!SkipAppClose) app?.Close();

src/Samples.UITest/Writer.Test/Views/SaveFileDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace UITest.Writer.Views;
66

77
public class SaveFileDialog(FrameworkAutomationElementBase element) : Window(element)
88
{
9-
public ComboBox FileName => this.Find("FileNameControlHost").AsComboBox();
9+
public ComboBox FileNameBox => this.Find("FileNameControlHost").AsComboBox();
1010

1111
public Button SaveButton => this.Find(x => x.ByControlType(ControlType.Button).And(x.ByAutomationId("1"))).AsButton();
1212

0 commit comments

Comments
 (0)