Skip to content

Commit 1e821b0

Browse files
[Testing] Written UI test for the issue resolved in PR 25453 (#25573)
* Automation sample for 25453. * Simplified the sample. * Removed platform conditions.
1 parent 8d00e9b commit 1e821b0

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue25504"
5+
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
6+
7+
<ListView x:Name="listView"
8+
AutomationId="listView"
9+
HeightRequest="50"
10+
ItemSelected="OnItemSelected">
11+
<ListView.ItemsSource>
12+
<x:Array Type="{x:Type x:String}">
13+
<x:String>Introduction to .NET MAUI</x:String>
14+
</x:Array>
15+
</ListView.ItemsSource>
16+
<ListView.ItemTemplate>
17+
<DataTemplate>
18+
<ViewCell>
19+
<Label Text="{Binding .}"
20+
AutomationId="Label"/>
21+
</ViewCell>
22+
</DataTemplate>
23+
</ListView.ItemTemplate>
24+
</ListView>
25+
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 25504, "ListView crashes when changing the root page inside the ItemSelected event", PlatformAffected.UWP)]
4+
public partial class Issue25504 : ContentPage
5+
{
6+
public Issue25504()
7+
{
8+
InitializeComponent();
9+
this.BindingContext = this;
10+
}
11+
12+
private void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
13+
{
14+
if (Application.Current?.Windows.Count > 0)
15+
{
16+
Application.Current.Windows[0].Page = new DetailsPage();
17+
}
18+
}
19+
20+
public class DetailsPage : ContentPage
21+
{
22+
public DetailsPage()
23+
{
24+
Content = new Label { Text = "Details Page", AutomationId = "DetailsPage" };
25+
}
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue25504 : _IssuesUITest
8+
{
9+
public override string Issue => "ListView crashes when changing the root page inside the ItemSelected event";
10+
11+
public Issue25504(TestDevice device)
12+
: base(device)
13+
{ }
14+
15+
[Test]
16+
[Category(UITestCategories.ListView)]
17+
public void ListViewShouldNotCrashWhenChangingRootPage()
18+
{
19+
App.WaitForElement("listView");
20+
App.Tap("Label");
21+
var testLabel = App.WaitForElement("DetailsPage");
22+
Assert.That(testLabel.GetText(), Is.EqualTo("Details Page"));
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)