Skip to content

Commit 651e9ed

Browse files
[Testing] Re-Enabled UI Test - Issue12574Test (#29436)
* re-enabled the test for android * modified test case * Update src/Controls/tests/TestCases.HostApp/Issues/CarouselViewLoopNoFreeze.cs Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 7583694 commit 651e9ed

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/Controls/tests/TestCases.HostApp/Issues/CarouselViewLoopNoFreeze.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class CarouselViewLoopNoFreeze : ContentPage
1111
readonly string _carouselAutomationId = "carouselView";
1212
readonly string _btnRemoveAutomationId = "btnRemove";
1313
readonly string _btnRemoveAllAutomationId = "btnRemoveAll";
14+
readonly string _btnSwipeAutomationId = "btnSwipe";
1415

1516
readonly ViewModelIssue12574 _viewModel;
1617
readonly CarouselView2 _carouselView;
1718
readonly Button _btn;
1819
readonly Button _btn2;
20+
readonly Button _btn3;
1921

2022
public CarouselViewLoopNoFreeze()
2123
{
@@ -33,6 +35,19 @@ public CarouselViewLoopNoFreeze()
3335
};
3436
_btn2.SetBinding(Button.CommandProperty, "RemoveAllItemsCommand");
3537

38+
_btn3 = new Button
39+
{
40+
Text = "Swipe",
41+
AutomationId = _btnSwipeAutomationId
42+
};
43+
_btn3.Clicked += (s, e) =>
44+
{
45+
if (_viewModel.Items.Count == 0)
46+
return;
47+
_viewModel.CurrentPosition = (_viewModel.CurrentPosition + 1) % _viewModel.Items.Count;
48+
_carouselView.ScrollTo(_viewModel.CurrentPosition);
49+
};
50+
3651
_carouselView = new CarouselView2
3752
{
3853
AutomationId = _carouselAutomationId,
@@ -62,11 +77,14 @@ public CarouselViewLoopNoFreeze()
6277
var layout = new Grid();
6378
layout.RowDefinitions.Add(new RowDefinition { Height = 100 });
6479
layout.RowDefinitions.Add(new RowDefinition { Height = 100 });
80+
layout.RowDefinitions.Add(new RowDefinition { Height = 100 });
6581
layout.RowDefinitions.Add(new RowDefinition());
6682
Grid.SetRow(_btn2, 1);
67-
Grid.SetRow(_carouselView, 2);
83+
Grid.SetRow(_btn3, 2);
84+
Grid.SetRow(_carouselView, 3);
6885
layout.Children.Add(_btn);
6986
layout.Children.Add(_btn2);
87+
layout.Children.Add(_btn3);
7088
layout.Children.Add(_carouselView);
7189

7290
BindingContext = _viewModel = new ViewModelIssue12574();
@@ -85,6 +103,16 @@ class ViewModelIssue12574 : BaseViewModel1
85103
public Command LoadItemsCommand { get; set; }
86104
public Command RemoveAllItemsCommand { get; set; }
87105
public Command RemoveLastItemCommand { get; set; }
106+
private int _currentPosition = 0;
107+
public int CurrentPosition
108+
{
109+
get => _currentPosition;
110+
set
111+
{
112+
_currentPosition = value;
113+
OnPropertyChanged(nameof(CurrentPosition));
114+
}
115+
}
88116

89117
public ViewModelIssue12574()
90118
{
@@ -110,6 +138,10 @@ void ExecuteRemoveLastItemCommand()
110138
Items.Remove(Items.Last());
111139
RemoveAllItemsCommand.ChangeCanExecute();
112140
RemoveLastItemCommand.ChangeCanExecute();
141+
if (CurrentPosition > 0)
142+
{
143+
CurrentPosition--;
144+
}
113145
}
114146

115147
void ExecuteLoadItemsCommand()

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CarouselViewUITests.LoopNoFreeze.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID // Related issue for windows: https://github.com/dotnet/maui/issues/24482 and For Android, see : https://github.com/dotnet/maui/issues/28760
1+
#if TEST_FAILS_ON_WINDOWS // Related issue for windows: https://github.com/dotnet/maui/issues/24482
22
using NUnit.Framework;
33
using UITest.Appium;
44
using UITest.Core;
@@ -10,6 +10,7 @@ public class CarouselViewLoopNoFreeze : _IssuesUITest
1010
readonly string _carouselAutomationId = "carouselView";
1111
readonly string _btnRemoveAutomationId = "btnRemove";
1212
readonly string _btnRemoveAllAutomationId = "btnRemoveAll";
13+
readonly string _btnSwipeAutomationId = "btnSwipe";
1314

1415
protected override bool ResetAfterEachTest => true;
1516
public CarouselViewLoopNoFreeze(TestDevice device)
@@ -28,10 +29,11 @@ public void Issue12574Test()
2829
App.WaitForElement("0 item");
2930

3031
App.WaitForElement(_carouselAutomationId);
31-
App.ScrollRight(_carouselAutomationId, ScrollStrategy.Gesture, 0.99);
32+
App.WaitForElement(_btnSwipeAutomationId);
33+
App.Tap(_btnSwipeAutomationId);
3234

3335
App.WaitForElement("1 item");
34-
App.ScrollRight(_carouselAutomationId, ScrollStrategy.Gesture, 0.99);
36+
App.Tap(_btnSwipeAutomationId);
3537

3638

3739
App.WaitForElement("2 item");
@@ -40,7 +42,7 @@ public void Issue12574Test()
4042

4143
App.WaitForElement("1 item");
4244

43-
App.ScrollRight(_carouselAutomationId, ScrollStrategy.Gesture, 0.99);
45+
App.Tap(_btnSwipeAutomationId);
4446

4547
App.WaitForElement("0 item");
4648
}

0 commit comments

Comments
 (0)