Skip to content

Commit

Permalink
UI test screenshot capture (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jbe2277 authored Apr 23, 2024
1 parent 8d5917c commit b0cfc4c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/NewsReader.CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- 'src/*'
- 'src/NewsReader/**'
- '.github/workflows/**'
- '!.github/workflows/System.Waf.CI.yml'

jobs:
GetVersion:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/System.Waf.CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ jobs:
run: dotnet build ./src/System.Waf/System.Waf.sln -c Release -p:ContinuousIntegrationBuild=true
- name: Test
run: dotnet test ./src/System.Waf/System.Waf.sln -c Release --no-build
- name: Upload NuGet packages
- name: Upload NuGet Packages
uses: actions/upload-artifact@v4
with:
name: packages
name: Packages
if-no-files-found: error
path: |
src/System.Waf/System.Waf/**/*.nupkg
src/System.Waf/System.Waf/**/*.snupkg
- name: UI Test
run: dotnet test ./src/Samples.UITest/Samples.UITest.sln --logger "console;verbosity=detailed"
- name: Upload UI Test results
uses: actions/upload-artifact@v4
if: always()
with:
name: UITestResults
if-no-files-found: ignore
path: |
out/Samples.UITest/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[Bb]in/
[Oo]bj/
[Aa]pp[Pp]ackages/
[Oo]ut/

# Unit test results
[Tt]est[Rr]esults
Expand Down
7 changes: 5 additions & 2 deletions src/Samples.UITest/Writer.Test/Tests/WriterTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Capturing;
using FlaUI.Core.Definitions;
using FlaUI.Core.Tools;
using UITest.Writer.Views;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void NewZoomWritePrintPreviewExitWithoutSave()
var fileRibbonMenu = window.FileRibbonMenu;
fileRibbonMenu.MenuButton.Click();
fileRibbonMenu.PrintPreviewMenuItem.Invoke();

var printPreviewTab = window.PrintPreviewTab;
Assert.True(printPreviewTab.IsSelected);
printPreviewTab.ZoomOutButton.Click();
Expand Down Expand Up @@ -109,7 +110,9 @@ public void NewSaveRestartOpenChangeAskToSave()
Log.WriteLine(saveFileDialog.GetTree());
Log.WriteLine("---------");
var fileName = GetTempFileName("rtf");
saveFileDialog.FileName.EditableText = fileName;
saveFileDialog.FileNameBox.EditableText = fileName;
Capture.Screen().ToFile(GetScreenshotFile("FullSaveScreen.png"));
saveFileDialog.CaptureToFile(GetScreenshotFile("SaveFileDialog.png"));
saveFileDialog.SaveButton.Click();

fileRibbonMenu.MenuButton.Click();
Expand Down
13 changes: 10 additions & 3 deletions src/Samples.UITest/Writer.Test/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace UITest.Writer;

public class UITest : IDisposable
{
private readonly string outPath;
private readonly string executable;
private readonly string testOutPath;
private readonly List<string> usedFiles = [];
private Application? app;

static UITest()
{
Mouse.MovePixelsPerMillisecond = 2;
Expand All @@ -29,14 +31,17 @@ public UITest(ITestOutputHelper log)
{
Log = log;
var assemblyPath = Assembly.GetAssembly(typeof(UITest))!.Location;
executable = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../out/Writer/Release/net8.0-windows/writer.exe"));

outPath = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../out/"));
executable = Path.Combine(outPath, "Writer/Release/net8.0-windows/writer.exe");
testOutPath = Path.Combine(outPath, "Samples.UITest/Writer/");
Directory.CreateDirectory(testOutPath);
Log.WriteLine($"OSVersion: {Environment.OSVersion}");
Log.WriteLine($"ProcessorCount: {Environment.ProcessorCount}");
Log.WriteLine($"MachineName: {Environment.MachineName}");
Log.WriteLine($"UserInteractive: {Environment.UserInteractive}");
Log.WriteLine($"AssemblyPath: {assemblyPath}");
Log.WriteLine($"Executable: {executable}");
Log.WriteLine($"TestOutPath: {testOutPath}");
Automation = new()
{
ConnectionTimeout = TimeSpan.FromSeconds(5)
Expand Down Expand Up @@ -67,6 +72,8 @@ public string GetTempFileName(string fileExtension)
return file;
}

public string GetScreenshotFile(string fileName) => Path.Combine(testOutPath, fileName);

public void Dispose()
{
if (!SkipAppClose) app?.Close();
Expand Down
2 changes: 1 addition & 1 deletion src/Samples.UITest/Writer.Test/Views/SaveFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UITest.Writer.Views;

public class SaveFileDialog(FrameworkAutomationElementBase element) : Window(element)
{
public ComboBox FileName => this.Find("FileNameControlHost").AsComboBox();
public ComboBox FileNameBox => this.Find("FileNameControlHost").AsComboBox();

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

Expand Down

0 comments on commit b0cfc4c

Please sign in to comment.