Add PlatformUno Frontend.

This commit is contained in:
2024-09-29 20:58:08 +02:00
parent 9e84a62c41
commit a8a797211a
160 changed files with 2852 additions and 2905 deletions

View File

@@ -0,0 +1,12 @@
namespace FrontendPlaformUno.UITests;
public class Constants
{
public readonly static string WebAssemblyDefaultUri = "http://localhost:5000/";
public readonly static string iOSAppName = "es.brentj.FrontendPlaformUno";
public readonly static string AndroidAppName = "es.brentj.FrontendPlaformUno";
public readonly static string iOSDeviceNameOrId = "iPad Pro (12.9-inch) (3rd generation)";
public readonly static Platform CurrentPlatform = Platform.Browser;
public readonly static Browser WebAssemblyBrowser = Browser.Chrome;
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Uno.UITest.Helpers" />
<PackageReference Include="Xamarin.UITest" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@
namespace FrontendPlaformUno.UITests;
public class Given_MainPage : TestBase
{
[Test]
public async Task When_SmokeTest()
{
// NOTICE
// To run UITests, Run the WASM target without debugger. Note
// the port that is being used and update the Constants.cs file
// in the UITests project with the correct port number.
// Add delay to allow for the splash screen to disappear
await Task.Delay(5000);
// Query for the SecondPageButton and then tap it
Query xamlButton = q => q.All().Marked("SecondPageButton");
App.WaitForElement(xamlButton);
App.Tap(xamlButton);
// Take a screenshot and add it to the test results
TakeScreenshot("After tapped");
}
}

View File

@@ -0,0 +1,5 @@
global using NUnit.Framework;
global using Uno.UITest;
global using Uno.UITest.Helpers.Queries;
global using Uno.UITests.Helpers;
global using Query = System.Func<Uno.UITest.IAppQuery, Uno.UITest.IAppQuery>;

View File

@@ -0,0 +1,82 @@
namespace FrontendPlaformUno.UITests;
public class TestBase
{
private IApp? _app;
static TestBase()
{
AppInitializer.TestEnvironment.AndroidAppName = Constants.AndroidAppName;
AppInitializer.TestEnvironment.WebAssemblyDefaultUri = Constants.WebAssemblyDefaultUri;
AppInitializer.TestEnvironment.iOSAppName = Constants.iOSAppName;
AppInitializer.TestEnvironment.AndroidAppName = Constants.AndroidAppName;
AppInitializer.TestEnvironment.iOSDeviceNameOrId = Constants.iOSDeviceNameOrId;
AppInitializer.TestEnvironment.CurrentPlatform = Constants.CurrentPlatform;
AppInitializer.TestEnvironment.WebAssemblyBrowser = Constants.WebAssemblyBrowser;
#if DEBUG
AppInitializer.TestEnvironment.WebAssemblyHeadless = false;
#endif
// Start the app only once, so the tests runs don't restart it
// and gain some time for the tests.
AppInitializer.ColdStartApp();
}
protected IApp App
{
get => _app!;
private set
{
_app = value;
Uno.UITest.Helpers.Queries.Helpers.App = value;
}
}
[SetUp]
public void SetUpTest()
{
App = AppInitializer.AttachToApp();
}
[TearDown]
public void TearDownTest()
{
TakeScreenshot("teardown");
}
public FileInfo TakeScreenshot(string stepName)
{
var title = $"{TestContext.CurrentContext.Test.Name}_{stepName}"
.Replace(" ", "_")
.Replace(".", "_");
var fileInfo = App.Screenshot(title);
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileInfo.Name);
if (fileNameWithoutExt != title && fileInfo.DirectoryName != null)
{
var destFileName = Path
.Combine(fileInfo.DirectoryName, title + Path.GetExtension(fileInfo.Name));
if (File.Exists(destFileName))
{
File.Delete(destFileName);
}
File.Move(fileInfo.FullName, destFileName);
TestContext.AddTestAttachment(destFileName, stepName);
fileInfo = new FileInfo(destFileName);
}
else
{
TestContext.AddTestAttachment(fileInfo.FullName, stepName);
}
return fileInfo;
}
}