Skip to content

Commit 937596a

Browse files
authored
Merge pull request #1134 from corbob/1109-flaui
(#1109) Add FlaUI tests for detection of Beta packages
2 parents d8203a7 + 6841f45 commit 937596a

16 files changed

Lines changed: 874 additions & 0 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ChocolateyGui.TestUtilities
2+
{
3+
/// <summary>
4+
/// Defines how the application under test should be started by the test fixture.
5+
/// </summary>
6+
public enum ApplicationStartMode
7+
{
8+
/// <summary>
9+
/// Do not start or stop the application as this is done outside.
10+
/// </summary>
11+
None,
12+
13+
/// <summary>
14+
/// Start the application before each test and close it after each test.
15+
/// </summary>
16+
OncePerTest,
17+
18+
/// <summary>
19+
/// Start the application once for the whole test fixture and close it when all tests are finished.
20+
/// </summary>
21+
OncePerFixture
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using FlaUI.Core.AutomationElements;
2+
using FlaUI.Core.Definitions;
3+
using System.Linq;
4+
5+
namespace ChocolateyGui.UITests
6+
{
7+
internal static class AutomationIds
8+
{
9+
internal const string ALL_VERSIONS_CHECK_BOX = "AllVersionsCheckBox";
10+
internal const string BACK_BUTTON = "Back";
11+
internal const string DIALOG = "PART_Dialog";
12+
internal const string PACKAGES_LIST = "Packages";
13+
internal const string PRERELEASE_CHECK_BOX = "PrereleaseCheckBox";
14+
internal const string SEARCH_TEXT_BOX = "SearchTextBox";
15+
internal const string SHOW_ABOUT_BUTTON = "ShowAbout";
16+
internal const string SHOW_SETTINGS_BUTTON = "ShowSettings";
17+
internal const string SOURCES_LIST_VIEW = "SourcesListView";
18+
internal const string VERSION_TEXT = "Version";
19+
20+
internal static AutomationElement[] LocateAllByText(this AutomationElement automationElement, string text)
21+
{
22+
return automationElement.FindAllDescendants(cf => cf.ByControlType(ControlType.Text).And(cf.ByName(text)));
23+
}
24+
25+
internal static AutomationElement LocateFirstByText(this AutomationElement automationElement, string text)
26+
{
27+
return automationElement.LocateAllByText(text).FirstOrDefault();
28+
}
29+
}
30+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using ChocolateyGui.TestUtilities;
2+
using ChocolateyGui.UITests.Screens;
3+
using FlaUI.Core;
4+
using FlaUI.Core.AutomationElements;
5+
using FlaUI.Core.Input;
6+
using FlaUI.Core.WindowsAPI;
7+
using NUnit.Framework;
8+
using System.Linq;
9+
using System.Threading;
10+
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
11+
12+
namespace ChocolateyGui.UITests
13+
{
14+
[TestFixture]
15+
public class BetaPackagesTests : ChocolateyGuiTestBase
16+
{
17+
private const string PACKAGE_UNDER_TEST = "mixedpackage";
18+
private const string LATEST_STABLE_VERSION = "2.0.0";
19+
private const string LATEST_BETA_VERSION = "2.1.0-beta-1";
20+
protected new ApplicationStartMode ApplicationStartMode => ApplicationStartMode.OncePerFixture;
21+
22+
private MainScreen MainScreen;
23+
private RemoteSourceScreen RemoteSourceScreen;
24+
25+
[SetUp]
26+
public void Arrange()
27+
{
28+
MainScreen = Application.GetMainWindow(Automation).As<MainScreen>();
29+
30+
RemoteSourceScreen = MainScreen.OpenAndGetRemoteSourceScreen("hermes");
31+
RemoteSourceScreen.FocusAndClearSearch();
32+
33+
Keyboard.Type(PACKAGE_UNDER_TEST);
34+
Thread.Sleep(500); // Sometimes this fails without a minor sleep when debugging...
35+
Keyboard.Press(VirtualKeyShort.ENTER);
36+
MainScreen.WaitForDialog();
37+
}
38+
39+
[Test]
40+
public void RemoteScreenFindsStableVersionOfDesiredPackage()
41+
{
42+
var packageList = RemoteSourceScreen.GetPackageList();
43+
44+
Assert.AreEqual(1, packageList.Length);
45+
46+
var targetPackage = packageList.FirstOrDefault();
47+
targetPackage.Click();
48+
Thread.Sleep(100); // Without waiting, sometimes this fails...
49+
targetPackage.DoubleClick();
50+
var versionItem = MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.VERSION_TEXT));
51+
52+
Assert.That(string.Equals(LATEST_STABLE_VERSION, versionItem.Name));
53+
}
54+
55+
[Test]
56+
public void RemoteScreenFindsPrereleaseVersionOfDesiredPackage()
57+
{
58+
MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.PRERELEASE_CHECK_BOX)).Click();
59+
MainScreen.WaitForDialog();
60+
61+
var packageList = RemoteSourceScreen.GetPackageList();
62+
63+
Assert.AreEqual(1, packageList.Length);
64+
65+
var targetPackage = packageList.FirstOrDefault();
66+
targetPackage.Click();
67+
Thread.Sleep(100);
68+
targetPackage.DoubleClick();
69+
var versionItem = MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.VERSION_TEXT));
70+
71+
Assert.That(string.Equals(LATEST_BETA_VERSION, versionItem.Name));
72+
}
73+
74+
[Test]
75+
public void RemoteScreenFindsAllStableVersionsOfDesiredPackage()
76+
{
77+
MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.ALL_VERSIONS_CHECK_BOX)).Click();
78+
MainScreen.WaitForDialog();
79+
80+
var packageList = RemoteSourceScreen.GetPackageList();
81+
82+
Assert.AreEqual(3, packageList.Length);
83+
84+
var targetPackage = packageList.FirstOrDefault();
85+
targetPackage.Click();
86+
Thread.Sleep(100);
87+
targetPackage.DoubleClick();
88+
var versionItem = MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.VERSION_TEXT));
89+
90+
Assert.That(string.Equals(LATEST_STABLE_VERSION, versionItem.Name));
91+
}
92+
93+
[Test]
94+
public void RemoteScreenFindsAllVersionsOfDesiredPackage()
95+
{
96+
MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.PRERELEASE_CHECK_BOX)).Click();
97+
MainScreen.WaitForDialog();
98+
99+
MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.ALL_VERSIONS_CHECK_BOX)).Click();
100+
MainScreen.WaitForDialog();
101+
102+
var packageList = RemoteSourceScreen.GetPackageList();
103+
104+
Assert.AreEqual(10, packageList.Length);
105+
106+
var targetPackage = packageList.FirstOrDefault();
107+
targetPackage.Click();
108+
Thread.Sleep(100);
109+
targetPackage.DoubleClick();
110+
var versionItem = MainScreen.FindFirstDescendant(cf => cf.ByAutomationId(AutomationIds.VERSION_TEXT));
111+
112+
Assert.That(string.Equals(LATEST_BETA_VERSION, versionItem.Name));
113+
}
114+
}
115+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net48</TargetFramework>
5+
<Configurations>Debug;Release;ReleaseOfficial</Configurations>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="FlaUI.UIA2" Version="5.0.0" />
10+
<PackageReference Include="NUnit" Version="3.14.0" />
11+
<PackageReference Include="NUnit3TestAdapter" Version="6.2.0" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using ChocolateyGui.TestUtilities;
2+
using FlaUI.Core;
3+
using FlaUI.Core.AutomationElements;
4+
using FlaUI.Core.Tools;
5+
using FlaUI.UIA2;
6+
using NUnit.Framework;
7+
using System;
8+
9+
namespace ChocolateyGui.UITests
10+
{
11+
public class ChocolateyGuiTestBase : FlaUITestBase
12+
{
13+
protected override AutomationBase GetAutomation()
14+
{
15+
var automation = new UIA2Automation();
16+
return automation;
17+
}
18+
19+
protected override Application StartApplication()
20+
{
21+
var testDirectory = TestContext.CurrentContext.TestDirectory.Replace(".UITests", "");
22+
var application = Application.Launch(System.IO.Path.Combine(testDirectory, "ChocolateyGUI.exe"));
23+
24+
var window = Retry.Find(
25+
() => application.GetMainWindow(Automation).FindFirstDescendant(cf => cf.ByAutomationId("PART_TitleBar")),
26+
new RetrySettings
27+
{
28+
Timeout = TimeSpan.FromSeconds(30),
29+
Interval = TimeSpan.FromMilliseconds(500),
30+
IgnoreException = true,
31+
ThrowOnTimeout = true,
32+
TimeoutMessage = "Could not start the application."
33+
});
34+
35+
window.WaitUntilClickable();
36+
return application;
37+
}
38+
}
39+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using ChocolateyGui.TestUtilities;
2+
using ChocolateyGui.UITests.Screens;
3+
using FlaUI.Core;
4+
using FlaUI.Core.AutomationElements;
5+
using NUnit.Framework;
6+
7+
namespace ChocolateyGui.UITests
8+
{
9+
10+
[TestFixture]
11+
public class ChocolateyGuiTests : ChocolateyGuiTestBase
12+
{
13+
protected new ApplicationStartMode ApplicationStartMode => ApplicationStartMode.OncePerFixture;
14+
15+
[Test]
16+
public void AboutScreenTest()
17+
{
18+
var mainScreen = Application.GetMainWindow(Automation).As<MainScreen>();
19+
20+
Assert.DoesNotThrow(() =>
21+
{
22+
var aboutScreen = mainScreen.OpenAndGetAboutScreen();
23+
aboutScreen.BackButton.Invoke();
24+
});
25+
}
26+
27+
[Test]
28+
public void SettingsScreenTest()
29+
{
30+
var mainScreen = Application.GetMainWindow(Automation).As<MainScreen>();
31+
32+
Assert.DoesNotThrow(() =>
33+
{
34+
var settingsScreen = mainScreen.OpenAndGetSettingsScreen();
35+
settingsScreen.BackButton.Invoke();
36+
});
37+
}
38+
39+
[Test]
40+
public void RemoteSourceScreenTest()
41+
{
42+
var mainScreen = Application.GetMainWindow(Automation).As<MainScreen>();
43+
44+
Assert.DoesNotThrow(() =>
45+
{
46+
var remoteSourceScreen = mainScreen.OpenAndGetRemoteSourceScreen("hermes");
47+
48+
var packageDetailsScreen = remoteSourceScreen.GetPackageDetailsScreen("absolute-extracted-path");
49+
50+
packageDetailsScreen.BackButton.Invoke();
51+
});
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)