Merge pull request #67 from Youssef1313/issues/63
feat!: Support AppDataMode for ColdStartApp and AttachToApp
This commit is contained in:
Коммит
66602da97b
|
@ -37,6 +37,7 @@ namespace Sample
|
|||
TestControls.Add(new TestControl("SetPropertyValue 01", "Sample.Shared.Tests.SetPropertyValue_Tests"));
|
||||
TestControls.Add(new TestControl("Element Selection 01", "Sample.Shared.Tests.Element_Selection_Tests_01"));
|
||||
TestControls.Add(new TestControl("Scroll 1", "Sample.Shared.Tests.Scroll_Tests"));
|
||||
TestControls.Add(new TestControl("AppDataMode 1", "Sample.Shared.Tests.AppDataMode_Tests"));
|
||||
}
|
||||
public ObservableCollection<TestControl> TestControls { get; } = new ObservableCollection<TestControl>();
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tests\AppDataMode_Tests.xaml.cs">
|
||||
<DependentUpon>AppDataMode_Tests.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tests\CheckBox_Tests.xaml.cs">
|
||||
<DependentUpon>CheckBox_Tests.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -57,6 +60,10 @@
|
|||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Tests\AppDataMode_Tests.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Tests\CheckBox_Tests.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<UserControl
|
||||
x:Class="Sample.Shared.Tests.AppDataMode_Tests"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Sample.Shared.Tests"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400">
|
||||
|
||||
<StackPanel>
|
||||
<Button x:Name="SetLocalSettingButton" Content="Set local setting" Click="OnSetLocalSettingClick" />
|
||||
<Button x:Name="GetLocalSettingButton" Content="Get local setting" Click="OnGetLocalSettingClick" />
|
||||
<TextBlock x:Name="LocalSettingValueTextBlock" Text="<INITIAL_VALUE>"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
|
@ -0,0 +1,33 @@
|
|||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace Sample.Shared.Tests
|
||||
{
|
||||
public sealed partial class AppDataMode_Tests : UserControl
|
||||
{
|
||||
public AppDataMode_Tests()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnSetLocalSettingClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ApplicationData.Current.LocalSettings.Values["MySetting"] = "MyValue";
|
||||
}
|
||||
|
||||
private void OnGetLocalSettingClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ApplicationData.Current.LocalSettings.Values.TryGetValue("MySetting", out var value))
|
||||
{
|
||||
LocalSettingValueTextBlock.Text = value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalSettingValueTextBlock.Text = "<NOT_SET>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
using NUnit.Framework;
|
||||
using Uno.UITest;
|
||||
using Uno.UITest.Helpers;
|
||||
using Uno.UITest.Helpers.Queries;
|
||||
using Uno.UITests.Helpers;
|
||||
using Xamarin.UITest.Configuration;
|
||||
using Query = System.Func<Uno.UITest.IAppQuery, Uno.UITest.IAppQuery>;
|
||||
|
||||
namespace Sample.UITests
|
||||
{
|
||||
public class AppDataModeTests // Intentionally doesn't inherit TestBase to customize ;)
|
||||
{
|
||||
[Test]
|
||||
public void AppDataModeTest()
|
||||
{
|
||||
TestBase.InitializeTestEnvrionment();
|
||||
|
||||
var app = OpenSample(AppDataMode.Clear);
|
||||
Assert.AreEqual("<INITIAL_VALUE>", app.Marked("LocalSettingValueTextBlock").GetDependencyPropertyValue<string>("Text"));
|
||||
app.Marked("SetLocalSettingButton").Tap();
|
||||
app.Marked("GetLocalSettingButton").Tap();
|
||||
Assert.AreEqual("MyValue", app.Marked("LocalSettingValueTextBlock").GetDependencyPropertyValue<string>("Text"));
|
||||
|
||||
app = OpenSample(AppDataMode.DoNotClear);
|
||||
app.Marked("GetLocalSettingButton").Tap();
|
||||
Assert.AreEqual("MyValue", app.Marked("LocalSettingValueTextBlock").GetDependencyPropertyValue<string>("Text"));
|
||||
|
||||
app = OpenSample(AppDataMode.Clear);
|
||||
app.Marked("GetLocalSettingButton").Tap();
|
||||
Assert.AreEqual("<NOT_SET>", app.Marked("LocalSettingValueTextBlock").GetDependencyPropertyValue<string>("Text"));
|
||||
}
|
||||
|
||||
private static IApp OpenSample(AppDataMode mode = AppDataMode.Clear)
|
||||
{
|
||||
var app = AppInitializer.ColdStartApp(mode);
|
||||
|
||||
Query selector = q => q.Marked("AppDataMode 1");
|
||||
app.WaitForElement(selector);
|
||||
app.Tap(selector);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,16 +15,7 @@ namespace Sample.UITests
|
|||
|
||||
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
|
||||
InitializeTestEnvrionment();
|
||||
|
||||
// Start the app only once, so the tests runs don't restart it
|
||||
// and gain some time for the tests.
|
||||
|
@ -41,6 +32,20 @@ namespace Sample.UITests
|
|||
}
|
||||
}
|
||||
|
||||
public static void InitializeTestEnvrionment()
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void StartApp()
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@ using NUnit.Framework;
|
|||
using Uno.UITest;
|
||||
using Uno.UITest.Helpers.Queries;
|
||||
using Uno.UITest.Xamarin.Extensions;
|
||||
using Xamarin.UITest.Configuration;
|
||||
|
||||
namespace Uno.UITests.Helpers
|
||||
{
|
||||
|
@ -50,10 +51,10 @@ namespace Uno.UITests.Helpers
|
|||
/// </summary>
|
||||
/// <remarks>This method is generally called from the type constructor of a test assembly.</remarks>
|
||||
/// <returns>An <see cref="IApp"/> instance representing the running application.</returns>
|
||||
public static IApp ColdStartApp()
|
||||
public static IApp ColdStartApp(AppDataMode mode = AppDataMode.DoNotClear)
|
||||
{
|
||||
var app = Xamarin.UITest.TestEnvironment.Platform == Xamarin.UITest.TestPlatform.Local
|
||||
? StartApp(alreadyRunningApp: false)
|
||||
? StartApp(alreadyRunningApp: false, mode)
|
||||
: null;
|
||||
|
||||
Uno.UITest.Helpers.Queries.Helpers.App = app;
|
||||
|
@ -65,9 +66,9 @@ namespace Uno.UITests.Helpers
|
|||
/// Attach to an already running application.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IApp"/> instance representing the running application.</returns>
|
||||
public static IApp AttachToApp()
|
||||
public static IApp AttachToApp(AppDataMode mode = AppDataMode.DoNotClear)
|
||||
{
|
||||
var app = StartApp(alreadyRunningApp: TestContext.CurrentContext.CurrentRepeatCount == 0);
|
||||
var app = StartApp(alreadyRunningApp: TestContext.CurrentContext.CurrentRepeatCount == 0, mode);
|
||||
|
||||
Uno.UITest.Helpers.Queries.Helpers.App = app;
|
||||
|
||||
|
@ -89,7 +90,7 @@ namespace Uno.UITests.Helpers
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private static IApp StartApp(bool alreadyRunningApp)
|
||||
private static IApp StartApp(bool alreadyRunningApp, AppDataMode mode)
|
||||
{
|
||||
var retries = 3;
|
||||
|
||||
|
@ -104,13 +105,13 @@ namespace Uno.UITests.Helpers
|
|||
case Xamarin.UITest.TestPlatform.TestCloudiOS:
|
||||
return Xamarin.UITest.ConfigureApp
|
||||
.iOS
|
||||
.StartApp(Xamarin.UITest.Configuration.AppDataMode.Clear)
|
||||
.StartApp(mode)
|
||||
.ToUnoApp();
|
||||
|
||||
case Xamarin.UITest.TestPlatform.TestCloudAndroid:
|
||||
return Xamarin.UITest.ConfigureApp
|
||||
.Android
|
||||
.StartApp(Xamarin.UITest.Configuration.AppDataMode.Clear)
|
||||
.StartApp(mode)
|
||||
.ToUnoApp();
|
||||
|
||||
default:
|
||||
|
@ -118,10 +119,10 @@ namespace Uno.UITests.Helpers
|
|||
switch(GetLocalPlatform())
|
||||
{
|
||||
case Platform.Android:
|
||||
return CreateAndroidApp(alreadyRunningApp);
|
||||
return CreateAndroidApp(alreadyRunningApp, mode);
|
||||
|
||||
case Platform.iOS:
|
||||
return CreateiOSApp(alreadyRunningApp);
|
||||
return CreateiOSApp(alreadyRunningApp, mode);
|
||||
|
||||
case Platform.Browser:
|
||||
if(alreadyRunningApp)
|
||||
|
@ -212,7 +213,7 @@ namespace Uno.UITests.Helpers
|
|||
}
|
||||
}
|
||||
|
||||
private static IApp CreateAndroidApp(bool alreadyRunningApp)
|
||||
private static IApp CreateAndroidApp(bool alreadyRunningApp, AppDataMode mode)
|
||||
{
|
||||
if(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ANDROID_HOME")))
|
||||
{
|
||||
|
@ -241,12 +242,12 @@ namespace Uno.UITests.Helpers
|
|||
|
||||
var app = alreadyRunningApp
|
||||
? androidConfig.ConnectToApp()
|
||||
: androidConfig.StartApp();
|
||||
: androidConfig.StartApp(mode);
|
||||
|
||||
return app.ToUnoApp();
|
||||
}
|
||||
|
||||
private static IApp CreateiOSApp(bool alreadyRunningApp)
|
||||
private static IApp CreateiOSApp(bool alreadyRunningApp, AppDataMode mode)
|
||||
{
|
||||
var iOSConfig = Xamarin.UITest.ConfigureApp
|
||||
.iOS
|
||||
|
@ -268,7 +269,7 @@ namespace Uno.UITests.Helpers
|
|||
|
||||
var app = alreadyRunningApp
|
||||
? iOSConfig.ConnectToApp()
|
||||
: iOSConfig.StartApp(Xamarin.UITest.Configuration.AppDataMode.DoNotClear);
|
||||
: iOSConfig.StartApp(mode);
|
||||
|
||||
return app.ToUnoApp();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче