Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Microsoft.Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Controls.Sample.Embedd
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.ManualTests", "src\Controls\tests\ManualTests\Controls.ManualTests.csproj", "{E2BFD1F1-07A8-8DBE-3661-894D0FE37D9C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITest.Appium.Tests", "src\TestUtils\tests\UITest.Appium.Tests\UITest.Appium.Tests.csproj", "{D4FAD399-8E9F-459C-A432-2E9D7BB91117}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4FAD399-8E9F-459C-A432-2E9D7BB91117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4FAD399-8E9F-459C-A432-2E9D7BB91117}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4FAD399-8E9F-459C-A432-2E9D7BB91117}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4FAD399-8E9F-459C-A432-2E9D7BB91117}.Release|Any CPU.Build.0 = Release|Any CPU
{95BA42B5-B00E-4986-B9B5-517140378452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95BA42B5-B00E-4986-B9B5-517140378452}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95BA42B5-B00E-4986-B9B5-517140378452}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -666,6 +672,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D4FAD399-8E9F-459C-A432-2E9D7BB91117} = {6998CAA1-11D4-46B2-B80F-0AC882F58124}
{95BA42B5-B00E-4986-B9B5-517140378452} = {E8AD265B-3C67-4640-AC58-A522F9FB3361}
{AF64451F-E2BD-41C2-B083-F60C26AE2A9F} = {50C758FE-4E10-409A-94F5-A75480960864}
{00A11C2F-969F-4964-8557-91ADF4B1523D} = {446EB407-57EB-441D-9ADB-1A006CBF672A}
Expand Down
71 changes: 71 additions & 0 deletions docs/UITesting-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,83 @@ dotnet build ./src/Provisioning/Provisioning.csproj -t:ProvisionAppium -p:SkipAp
- Set `JAVA_HOME` environment variable
- Install Android API 30 SDK with x86/x64 emulator image

#### Launch directly to a test page

The Android HostApp accepts a `test` string intent extra containing the exact
issue description (from `IssueAttribute`) or gallery title, matched
case-insensitively. For example, after installing the HostApp:

```bash
adb shell am start -S -n com.microsoft.maui.uitests/com.microsoft.maui.uitests.MainActivity --es test '"Direct test launch"'
```

This creates the requested page as the initial window page without searching or
tapping through the gallery. Use `-S` to stop the existing app before launching:
the extra is read when the window is created, not when an already-running activity
is brought to the foreground. Omit `--es test ...` for normal gallery startup.
An empty or unrecognized test also opens the gallery; an unrecognized test is
reported in debug output.

### iOS/MacCatalyst-Specific

- macOS required
- Xcode with command-line tools installed
- iOS Simulator configured

#### Launch directly on iOS

iOS and MacCatalyst use the `test` environment variable with the same exact issue
description or gallery title. After installing the iOS HostApp on a simulator:

```bash
SIMCTL_CHILD_test="Direct test launch" xcrun simctl launch --terminate-running-process <simulator-udid> com.microsoft.maui.uitests
```

For a manually launched MacCatalyst app, set `test` in the app process's environment.
On Windows, pass the description or gallery title as one `--test=...` command-line
argument:

```powershell
.\Controls.TestCases.HostApp.exe '--test=Direct test launch'
```

On all platforms, missing, empty, or unrecognized startup targets open the normal
gallery. Unknown targets are reported in debug output. A startup target is consumed
when the initial window is created, so terminate the previous app instance before
changing it.

### Direct launch in the UI test runner

`_IssuesUITest` and `_GalleryUITest` configure their startup targets automatically
on Android, iOS, and MacCatalyst.
Fixture setup no longer searches for and taps the gallery's Go To Test button.
Resets relaunch the current fixture's target, including fixtures that set
`ResetAfterEachTest`; gallery subpage buttons are still selected after launch.
Fixture teardown closes the app rather than launching an unused gallery.
Tests of normal gallery startup can derive directly from `UITest` instead.

Starting a new test and resetting the app stop with an explicit error if the
previous app cannot be terminated. OS-command fallback termination succeeds only
when the command starts, completes within its timeout, and exits with code zero; a failed command
must not be treated as a successful close.

Android, iOS, and MacCatalyst reuse the driver session and send the current target
with each app launch. Android forwards the configured device UDID to Appium as
well, so multiple running emulators do not select the wrong device. Windows uses
`appArguments`; because WinAppDriver cannot change these capabilities on an
existing session, changing the startup target recreates that session. Windows
therefore retains gallery navigation by default until its native timing is
validated; set `MAUI_UITEST_DIRECT_LAUNCH=true` to opt into direct fixture startup.
Set it to `false` on any platform to compare the legacy navigation path.
Do not infer a Windows speedup from eliminating gallery navigation alone.

The startup argument, session reuse, and launch-command unit tests run without
native UI automation:

```bash
dotnet test src/TestUtils/tests/UITest.Appium.Tests/UITest.Appium.Tests.csproj
```

## Creating a UI Test

### Step 1: Create the HostApp Page
Expand Down
8 changes: 4 additions & 4 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
<MicrosoftWindowsWebView2PackageVersion>1.0.4258.31</MicrosoftWindowsWebView2PackageVersion>
<!-- Everything else -->
<MicrosoftAspNetCoreAuthorizationPackageVersion>10.0.0</MicrosoftAspNetCoreAuthorizationPackageVersion>
<MicrosoftAspNetCoreAuthenticationFacebookPackageVersion>10.0.13</MicrosoftAspNetCoreAuthenticationFacebookPackageVersion>
<MicrosoftAspNetCoreAuthenticationGooglePackageVersion>10.0.13</MicrosoftAspNetCoreAuthenticationGooglePackageVersion>
<MicrosoftAspNetCoreAuthenticationMicrosoftAccountPackageVersion>10.0.13</MicrosoftAspNetCoreAuthenticationMicrosoftAccountPackageVersion>
<MicrosoftAspNetCoreAuthenticationFacebookPackageVersion>10.0.14</MicrosoftAspNetCoreAuthenticationFacebookPackageVersion>
<MicrosoftAspNetCoreAuthenticationGooglePackageVersion>10.0.14</MicrosoftAspNetCoreAuthenticationGooglePackageVersion>
<MicrosoftAspNetCoreAuthenticationMicrosoftAccountPackageVersion>10.0.14</MicrosoftAspNetCoreAuthenticationMicrosoftAccountPackageVersion>
<MicrosoftAspNetCoreComponentsAnalyzersPackageVersion>10.0.0</MicrosoftAspNetCoreComponentsAnalyzersPackageVersion>
<MicrosoftAspNetCoreComponentsFormsPackageVersion>10.0.0</MicrosoftAspNetCoreComponentsFormsPackageVersion>
<MicrosoftAspNetCoreComponentsPackageVersion>10.0.0</MicrosoftAspNetCoreComponentsPackageVersion>
Expand All @@ -89,7 +89,7 @@
<MicrosoftAspNetCoreMetadataPackageVersion>10.0.0</MicrosoftAspNetCoreMetadataPackageVersion>
<MicrosoftJSInteropPackageVersion>10.0.0</MicrosoftJSInteropPackageVersion>
<!-- Everything else (previous edition) -->
<MicrosoftAspNetCorePackageVersion>10.0.10</MicrosoftAspNetCorePackageVersion>
<MicrosoftAspNetCorePackageVersion>10.0.14</MicrosoftAspNetCorePackageVersion>
<MicrosoftAspNetCoreAuthorizationPreviousPackageVersion>$(MicrosoftAspNetCorePackageVersion)</MicrosoftAspNetCoreAuthorizationPreviousPackageVersion>
<MicrosoftAspNetCoreAuthenticationFacebookPreviousPackageVersion>$(MicrosoftAspNetCorePackageVersion)</MicrosoftAspNetCoreAuthenticationFacebookPreviousPackageVersion>
<MicrosoftAspNetCoreAuthenticationGooglePreviousPackageVersion>$(MicrosoftAspNetCorePackageVersion)</MicrosoftAspNetCoreAuthenticationGooglePreviousPackageVersion>
Expand Down
1 change: 1 addition & 0 deletions eng/helix.proj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<XUnitProject Include="$(RepoRoot)src/Core/tests/UnitTests/Core.UnitTests.csproj" />
<XUnitProject Include="$(RepoRoot)src/Essentials/test/UnitTests/Essentials.UnitTests.csproj" />
<XUnitProject Include="$(RepoRoot)src/Graphics/tests/Graphics.Tests/Graphics.Tests.csproj" />
<XUnitProject Include="$(RepoRoot)src/TestUtils/tests/UITest.Appium.Tests/UITest.Appium.Tests.csproj" />
<XUnitProject Include="$(RepoRoot)src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiBlazorWebView.UnitTests.csproj" />
<XUnitProject Condition="$(HelixTargetQueue.StartsWith('Windows'))" Include="$(RepoRoot)src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/BlazorWebView.Windows.UnitTests.csproj">
<TargetFramework>$(_MauiDotNetTfm)-windows</TargetFramework>
Expand Down
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32463.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32463, "Direct test launch", PlatformAffected.All)]
public class Issue32463 : ContentPage
{
public Issue32463()
{
var count = 0;
var label = new Label
{
Text = "Launched directly to the test",
AutomationId = "DirectLaunchLabel"
};
var counter = new Label { Text = "0", AutomationId = "LaunchCounter" };
var windows = new Label { Text = Application.Current.Windows.Count.ToString(), AutomationId = "StartupWindowCount" };
var button = new Button { Text = "Increment", AutomationId = "IncrementCounter" };
button.Clicked += (_, _) => counter.Text = (++count).ToString();
Content = new VerticalStackLayout { Children = { label, counter, windows, button } };
}
}
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue39693.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue39693">
<Grid RowDefinitions="Auto,*">
<Label x:Name="Status" AutomationId="OrientationStateStatus" />
<Grid x:Name="controlsGrid" Grid.Row="1" RowSpacing="15" BackgroundColor="Orange">
<Button Text="Button 1" Grid.Row="0" Grid.Column="0" />
<Button Text="Button 2" Grid.Row="1" Grid.Column="0" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Portrait">
<VisualState.StateTriggers>
<OrientationStateTrigger Orientation="Portrait" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Green" />
<Setter Property="RowDefinitions" Value="40,120,*" />
<Setter Property="ColumnDefinitions" Value="*" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Landscape">
<VisualState.StateTriggers>
<OrientationStateTrigger Orientation="Landscape" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Black" />
<Setter Property="RowDefinitions" Value="40,*" />
<Setter Property="ColumnDefinitions" Value="*,50" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Grid>
</ContentPage>
25 changes: 25 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue39693.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 39693, "OrientationStateTriggers are broken with iOS 27", PlatformAffected.iOS)]
public partial class Issue39693 : ContentPage
{
public Issue39693()
{
InitializeComponent();
Loaded += (_, _) => UpdateStatus();
controlsGrid.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(BackgroundColor) ||
e.PropertyName == nameof(Grid.RowDefinitions) ||
e.PropertyName == nameof(Grid.ColumnDefinitions))
UpdateStatus();
};
}

void UpdateStatus() => Dispatcher.Dispatch(() =>
{
var color = controlsGrid.BackgroundColor;
var colorName = color == Colors.Green ? "Green" : color == Colors.Black ? "Black" : "Orange";
Status.Text = $"{colorName}; rows={controlsGrid.RowDefinitions.Count}; columns={controlsGrid.ColumnDefinitions.Count}";
});
}
14 changes: 11 additions & 3 deletions src/Controls/tests/TestCases.HostApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ public static Page CreateDefaultMainPage()
{
Page mainPage = null;
OverrideMainPage(ref mainPage);
#if MACCATALYST
// Check for startup test argument from environment variables (passed by test runner)
#if ANDROID
var testName = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.Intent?.GetStringExtra("test");
#elif IOS || MACCATALYST
var testName = System.Environment.GetEnvironmentVariable("test");

#elif WINDOWS
const string testArgument = "--test=";
var testName = Environment.GetCommandLineArgs()
.FirstOrDefault(argument => argument.StartsWith(testArgument, StringComparison.Ordinal))?[testArgument.Length..];
#endif
#if ANDROID || IOS || MACCATALYST || WINDOWS
if (!string.IsNullOrEmpty(testName))
{
// Try to get the test page directly from issues/test cases
Expand All @@ -120,6 +126,8 @@ public static Page CreateDefaultMainPage()
// Return the gallery page
return galleryPage;
}

Debug.WriteLine($"No test or gallery page found for startup test '{testName}'.");
}
#endif
return mainPage ?? new CoreNavigationPage();
Expand Down
41 changes: 19 additions & 22 deletions src/Controls/tests/TestCases.HostApp/TestCases.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Linq;
using System.Reflection;

namespace Maui.Controls.Sample
{
Expand All @@ -10,27 +10,27 @@ public class TestCaseScreen : CollectionView
{
public static Dictionary<string, Action> PageToAction = new Dictionary<string, Action>(StringComparer.OrdinalIgnoreCase);

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
bool _filterBugzilla;
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
bool _filterNone;
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
bool _filterGitHub;
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
bool _filterManual;
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
string _filter;

void CheckInternetAndLoadPage(Type type)
Page CheckInternetAndGetPage(Type type)
{
try
{
Expand All @@ -42,21 +42,18 @@ void CheckInternetAndLoadPage(Type type)
httpResponse.Wait();
if (httpResponse.Result.IsSuccessStatusCode)
{
var page = ActivatePage(type);
Application.Current.Windows[0].Page = page;
return ActivatePage(type);
}
else
{
var noInternetConnectionPage = ActivatePage(typeof(NoInternetConnectionPage));
Application.Current.Windows[0].Page = noInternetConnectionPage;
return ActivatePage(typeof(NoInternetConnectionPage));
}
}
}
}
catch
{
var noInternetConnectionPage = ActivatePage(typeof(NoInternetConnectionPage));
Application.Current.Windows[0].Page = noInternetConnectionPage;
return ActivatePage(typeof(NoInternetConnectionPage));
}
}

Expand All @@ -68,7 +65,7 @@ Action ActivatePageAndNavigate(IssueAttribute issueAttribute, Type type)
{
return () =>
{
CheckInternetAndLoadPage(type);
Application.Current.Windows[0].Page = CheckInternetAndGetPage(type);
};
}

Expand Down Expand Up @@ -103,7 +100,7 @@ Action ActivatePageAndNavigate(IssueAttribute issueAttribute, Type type)
return navigationAction;
}

[UnconditionalSuppressMessage("TrimAnalysis", "IL2026",
[UnconditionalSuppressMessage("TrimAnalysis", "IL2026",
Justification = "ActivatePage method is only called in non-NativeAOT builds where reflection-based test discovery is enabled.")]
Page ActivatePage([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type)
{
Expand Down Expand Up @@ -154,7 +151,7 @@ public bool Matches(string filter)
}
}

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
readonly List<IssueModel> _issues;

Expand Down Expand Up @@ -199,7 +196,7 @@ public TestCaseScreen()
IsInternetRequired = attribute.IsInternetRequired,
Action = ActivatePageAndNavigate(attribute, type),
// PageFactory is used to retrieve the instance of the page.
PageFactory = () => ActivatePage(type)
PageFactory = () => attribute.IsInternetRequired ? CheckInternetAndGetPage(type) : ActivatePage(type)
}).ToList();
#endif

Expand Down Expand Up @@ -361,7 +358,7 @@ from issueModel in _issues
ItemsSource = issues;
}

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
HashSet<string> _exemptNames = new HashSet<string> { };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ protected override void FixtureSetup()
try
{
base.FixtureSetup();
#if MACCATALYST
NavigateToGallery();
#endif
break;
}
catch (Exception e)
Expand Down
Loading
Loading