forked from Roflin/gamenight
Added initial Uno Platform frontend project.
This commit is contained in:
12
FrontendPlatformUno/FrontendPlatformUno.UITests/Constants.cs
Normal file
12
FrontendPlatformUno/FrontendPlatformUno.UITests/Constants.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace FrontendPlatformUno.UITests
|
||||
{
|
||||
public class Constants
|
||||
{
|
||||
public readonly static string WebAssemblyDefaultUri = "http://localhost:5000/";
|
||||
public readonly static string iOSAppName = "FrontendPlatformUno";
|
||||
public readonly static string AndroidAppName = "FrontendPlatformUno";
|
||||
public readonly static string iOSDeviceNameOrId = "iPad Pro (12.9-inch) (3rd generation)";
|
||||
|
||||
public readonly static Platform CurrentPlatform = Platform.Browser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.10.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
|
||||
<PackageReference Include="Uno.UITest.Helpers" Version="1.1.0-dev.32" />
|
||||
<PackageReference Include="Xamarin.UITest" Version="4.1.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace FrontendPlatformUno.UITests
|
||||
{
|
||||
public class Given_MainPage : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void 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.
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
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>;
|
||||
|
||||
82
FrontendPlatformUno/FrontendPlatformUno.UITests/TestBase.cs
Normal file
82
FrontendPlatformUno/FrontendPlatformUno.UITests/TestBase.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
namespace FrontendPlatformUno.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;
|
||||
|
||||
#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)
|
||||
{
|
||||
var destFileName = Path
|
||||
.Combine(Path.GetDirectoryName(fileInfo.FullName), 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user