Skip to content

Commit

Permalink
Fixup UI tests (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jul 26, 2024
1 parent d89ed98 commit 5c43090
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/SerialLoops/SerialLoops.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<ItemGroup>
<PackageReference Include="Eto.Forms" Version="2.8.3" />
<PackageReference Include="Eto.Forms.Controls.SkiaSharp.Shared" Version="2.0.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/SerialLoops/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/SerialLoops/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -122,6 +122,7 @@
</data>
<data name="%" xml:space="preserve">
<value>%</value>
<comment>Just the percentage symbol</comment>
</data>
<data name="&amp;Build" xml:space="preserve">
<value>&amp;Build</value>
Expand All @@ -143,6 +144,7 @@
</data>
<data name="(Missing)" xml:space="preserve">
<value> (Missing)</value>
<comment>For when a project file has been deleted</comment>
</data>
<data name="100%'d game message box" xml:space="preserve">
<value>100%'d game message box</value>
Expand Down Expand Up @@ -788,6 +790,7 @@
</data>
<data name="Error getting script command tree for script {0} ({1})" xml:space="preserve">
<value>Error getting script command tree for script {0} ({1})</value>
<comment>{0} is the script display name, {1} is the script's underlying name</comment>
</data>
<data name="Error pruning labels!" xml:space="preserve">
<value>Error pruning labels!</value>
Expand Down Expand Up @@ -1047,6 +1050,7 @@
</data>
<data name="Flag: {0}" xml:space="preserve">
<value>Flag: {0}</value>
<comment>{0} is the ID of the flag</comment>
</data>
<data name="Flags" xml:space="preserve">
<value>Flags</value>
Expand Down Expand Up @@ -1350,6 +1354,7 @@
</data>
<data name="Name '{0}' is already in use!" xml:space="preserve">
<value>Name '{0}' is already in use!</value>
<comment>{0} is the name of an item (this appears when attempting to rename an item)</comment>
</data>
<data name="NDS ROM" xml:space="preserve">
<value>NDS ROM</value>
Expand All @@ -1374,6 +1379,7 @@
</data>
<data name="New Update Available: {0}" xml:space="preserve">
<value>New Update Available: {0}</value>
<comment>{0} is the version</comment>
</data>
<data name="NitroPacker failed to pack ROM with exception" xml:space="preserve">
<value>NitroPacker failed to pack ROM with exception</value>
Expand Down Expand Up @@ -2361,19 +2367,23 @@
</data>
<data name="{0} - Adjust Volume" xml:space="preserve">
<value>{0} - Adjust Volume</value>
<comment>{0} is the title of a BGM track</comment>
</data>
<data name="{0} - Manage Loop" xml:space="preserve">
<value>{0} - Manage Loop</value>
<comment>{0} is the title of a BGM track</comment>
</data>
<data name="{0} Obtained" xml:space="preserve">
<value>{0} Obtained</value>
<comment>{0} is the name of a topic that's been obtained</comment>
</data>
<data name="{0} results" xml:space="preserve">
<value>{0} results</value>
<comment>{0} is the number of flags found</comment>
</data>
<data name="{0} results found" xml:space="preserve">
<value>{0} results found</value>
<comment>{0} is the number of search results</comment>
</data>
<data name="{0} Watched in Extras" xml:space="preserve">
<value>{0} Watched in Extras</value>
Expand Down
21 changes: 21 additions & 0 deletions test/SerialLoops.Tests.Shared/UiVals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
{
public class UiVals
{
public const string ROM_URI_ENV_VAR = "ROM_URI";
public const string ROM_NAME = "HaruhiChokuretsu.nds";
public const string APP_LOCATION_ENV_VAR = "APP_LOCATION";
public const string PROJECT_NAME_ENV_VAR = "PROJECT_NAME";
public const string ARTIFACTS_DIR_ENV_VAR = "BUILD_ARTIFACTSTAGINGDIRECTORY";
public const string APPIUM_HOST_ENV_VAR = "APPIUM_HOST";

public const string SKIP_UPDATE = "Skip Update";
public const string NEW_PROJECT = "New Project";
public const string OPEN_ROM = "Open ROM";
public const string CREATE = "Create";
public const string FILE = "File";
public const string ABOUT_ELLIPSIS = "About…";
public const string ABOUT = "About";
public const string PREFERENCES = "Preferences…";
public const string USE_DOCKER_FOR_ASM_HACKS = "Use Docker for ASM Hacks";
public const string SAVE = "Save";
public const string TOOLS = "Tools";
public const string OK = "OK";
public const string APPLY_HACKS = "Apply Hacks…";

public string AppLoc { get; set; } = string.Empty;
public string ProjectName { get; set; } = string.Empty;
public string WinAppDriverLoc { get; set; } = string.Empty;
Expand Down
36 changes: 18 additions & 18 deletions test/ui/SerialLoops.Mac.Tests/MacUITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void Setup()
}
else
{
string romUri = Environment.GetEnvironmentVariable("ROM_URI") ?? string.Empty;
string romPath = Path.Combine(Directory.GetCurrentDirectory(), "HaruhiChokuretsu.nds");
string romUri = Environment.GetEnvironmentVariable(UiVals.ROM_URI_ENV_VAR) ?? string.Empty;
string romPath = Path.Combine(Directory.GetCurrentDirectory(), UiVals.ROM_NAME);
HttpClient httpClient = new();
using Stream downloadStream = httpClient.Send(new() { Method = HttpMethod.Get, RequestUri = new(romUri) }).Content.ReadAsStream();
using FileStream fileStream = new(romPath, FileMode.Create);
Expand All @@ -48,10 +48,10 @@ public void Setup()

_uiVals = new()
{
AppLoc = Environment.GetEnvironmentVariable("APP_LOCATION") ?? string.Empty,
ProjectName = Environment.GetEnvironmentVariable("PROJECT_NAME") ?? "MacUITest",
AppLoc = Environment.GetEnvironmentVariable(UiVals.APP_LOCATION_ENV_VAR) ?? string.Empty,
ProjectName = Environment.GetEnvironmentVariable(UiVals.PROJECT_NAME_ENV_VAR) ?? "MacUITest",
RomLoc = romPath,
ArtifactsDir = Environment.GetEnvironmentVariable("BUILD_ARTIFACTSTAGINGDIRECTORY") ?? "artifacts",
ArtifactsDir = Environment.GetEnvironmentVariable(UiVals.ARTIFACTS_DIR_ENV_VAR) ?? "artifacts",
};
}
_logger.Log(JsonSerializer.Serialize(_uiVals, new JsonSerializerOptions { WriteIndented = true }));
Expand All @@ -69,10 +69,10 @@ public void Setup()

Thread.Sleep(TimeSpan.FromSeconds(5));
_driver.GetScreenshot().SaveAsFile(Path.Combine(_uiVals.ArtifactsDir, "start.png"));
_driver.FindElement(MobileBy.IosClassChain("XCUIElementTypeDialog/**/XCUIElementTypeButton[`title == \"Skip Update\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeStaticText[`value == \"New Project\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"XCUIElementTypeDialog/**/XCUIElementTypeButton[`title == \"{UiVals.SKIP_UPDATE}\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeStaticText[`value == \"{UiVals.NEW_PROJECT}\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain("XCUIElementTypeDialog/**/XCUIElementTypeTextField[1]")).SendKeys(_uiVals.ProjectName);
_driver.FindElement(MobileBy.IosClassChain("XCUIElementTypeDialog/**/XCUIElementTypeButton[`title == \"Open ROM\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"XCUIElementTypeDialog/**/XCUIElementTypeButton[`title == \"{UiVals.OPEN_ROM}\"`]")).Click();
AppiumElement openFileDialog = _driver.FindElement(MobileBy.IosNSPredicate("label == \"open\""));
openFileDialog.SendKeys($"{Keys.Command}{Keys.Shift}g/");
openFileDialog.SendKeys(_uiVals.RomLoc[1..]);
Expand All @@ -85,7 +85,7 @@ public void Setup()
Thread.Sleep(500);
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeSheet[`label == \"open\"`]/**/XCUIElementTypeButton[`title == \"Open\"`]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(1));
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeButton[`title == \"Create\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeButton[`title == \"{UiVals.CREATE}\"`]")).Click();
while (_driver.FindElements(MobileBy.IosClassChain("**/XCUIElementTypeDialog")).Count >= 1)
{
Thread.Sleep(TimeSpan.FromSeconds(5));
Expand Down Expand Up @@ -123,7 +123,7 @@ public void CanOpenAboutDialogTwice()
{
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuBarItem[`title=\"SerialLoops\"`]")).Click();
Thread.Sleep(200);
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuItem[`title=\"About...\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeMenuItem[`title=\"{UiVals.ABOUT_ELLIPSIS}\"`]")).Click();
Thread.Sleep(200);
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeDialog[`title=\"About\"`]/**/XCUIElementTypeButton[1]")).Click();
Thread.Sleep(200);
Expand All @@ -136,44 +136,44 @@ public void CanOpenAboutDialogTwice()
[Test, TestCaseSource(nameof(HacksToTest))]
public void TestAsmHackApplicationAndReversion(string hackToApply)
{
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuBarItem[`title=\"Tools\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeMenuBarItem[`title=\"{UiVals.TOOLS}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "tools_clicked.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals.ArtifactsDir, "tools_clicked.png"), "The app after the tools menu was clicked but before clicking Apply Hacks");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuItem[`title=\"Apply Hacks...\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeMenuItem[`title=\"{UiVals.APPLY_HACKS}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "available_hacks.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, "available_hacks.png"), "The available hacks dialog");
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeCheckBox[`title=\"{hackToApply}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, $"applying_hack_{hackToApply.Replace(' ', '_')}.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, $"applying_hack_{hackToApply.Replace(' ', '_')}.png"), $"Applying the hack {hackToApply}");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeDialog[`title=\"Apply Assembly Hacks\"`]/**/XCUIElementTypeButton[`title=\"Save\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeDialog[`title=\"Apply Assembly Hacks\"`]/**/XCUIElementTypeButton[`title=\"{UiVals.SAVE}\"`]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(10)); // Allow time for hacks to be assembled
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "hack_apply_result_dialog.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, "hack_apply_result_dialog.png"), "The alert indicating whether the hack application succeeded or not");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeDialog[`label=\"alert\"`]/**/XCUIElementTypeButton[`title=\"OK\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeDialog[`label=\"alert\"`]/**/XCUIElementTypeButton[`title=\"{UiVals.OK}\"`]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(1)); // Allow time to clean up the containers
List<AsmHack> hacks = JsonSerializer.Deserialize<List<AsmHack>>(File.ReadAllText(Path.Combine("Sources", "hacks.json"))) ?? [];
Assert.That(hacks.First(h => h.Name == hackToApply).Applied(_project), Is.True);

_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuBarItem[`title=\"Tools\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeMenuBarItem[`title=\"{UiVals.TOOLS}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "tools_clicked.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals.ArtifactsDir, "tools_clicked.png"), "The app after the tools menu was clicked but before clicking Apply Hacks");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeMenuItem[`title=\"Apply Hacks...\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeMenuItem[`title=\"{UiVals.APPLY_HACKS}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "available_hacks.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, "available_hacks.png"), "The available hacks dialog");
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeCheckBox[`title=\"{hackToApply}\"`]")).Click();
Thread.Sleep(200);
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, $"applying_hack_{hackToApply.Replace(' ', '_')}.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, $"applying_hack_{hackToApply.Replace(' ', '_')}.png"), $"Applying the hack {hackToApply}");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeDialog[`title=\"Apply Assembly Hacks\"`]/**/XCUIElementTypeButton[`title=\"Save\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeDialog[`title=\"Apply Assembly Hacks\"`]/**/XCUIElementTypeButton[`title=\"{UiVals.SAVE}\"`]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(5)); // Allow time for hacks to be reverted
_driver.TakeScreenshot().SaveAsFile(Path.Combine(_uiVals!.ArtifactsDir, "hack_apply_result_dialog.png"));
TestContext.AddTestAttachment(Path.Combine(_uiVals!.ArtifactsDir, "hack_apply_result_dialog.png"), "The alert indicating whether the hack application succeeded or not");
_driver.FindElement(MobileBy.IosClassChain("**/XCUIElementTypeDialog[`label=\"alert\"`]/**/XCUIElementTypeButton[`title=\"OK\"`]")).Click();
_driver.FindElement(MobileBy.IosClassChain($"**/XCUIElementTypeDialog[`label=\"alert\"`]/**/XCUIElementTypeButton[`title=\"{UiVals.OK}\"`]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(1)); // Allow time to clean up the containers
Assert.That(hacks.First(h => h.Name == hackToApply).Applied(_project), Is.False);
}
Expand Down
4 changes: 0 additions & 4 deletions test/ui/SerialLoops.Wpf.Tests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using OpenQA.Selenium.Appium.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Wpf.Tests
{
Expand Down
Loading

0 comments on commit 5c43090

Please sign in to comment.