Skip to content

Commit 80a7fcf

Browse files
Anandhan RajagopalNafeelaNazhirnivetha-nagalingam
authored
[Testing] Enabling ported UITests from Xamarin.UITests to Appium - 50 (#26634)
* Enabled 50th set of UITest migration from XamarinUITest into Appium (#52) * Migrated Issue 12429 and MapsModalCrash * Added comments for Issue 12429 * Migrated Issue ShellFlyoutHeaderBehavior and Issue 10134 * Modified the enabled tests * Enabled 50th Set of UITests migrated from XamarinUITest into Appium (#51) * Migrated the Bugzilla 31333, 40955 and 43469 * Modifed the enabled tests * Updated Bugzilla40955 * Updated the comments --------- Co-authored-by: nivetha-nagalingam <[email protected]> --------- Co-authored-by: NafeelaNazhir <[email protected]> Co-authored-by: nivetha-nagalingam <[email protected]> * Skip the test which fails on CI. --------- Co-authored-by: NafeelaNazhir <[email protected]> Co-authored-by: nivetha-nagalingam <[email protected]>
1 parent f249086 commit 80a7fcf

File tree

11 files changed

+320
-276
lines changed

11 files changed

+320
-276
lines changed

src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla31333.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ public void SetBinding()
120120

121121
public class ExtendedCell<T> : ViewCell where T : View, IHaveControlFocusedProperty
122122
{
123-
public ExtendedCell()
123+
public ExtendedCell(string automationId = null)
124124
{
125125
var control = (T)Activator.CreateInstance(typeof(T));
126126
control.SetBinding();
127127
#pragma warning disable CS0618 // Type or member is obsolete
128128
control.HorizontalOptions = LayoutOptions.FillAndExpand;
129129
#pragma warning restore CS0618 // Type or member is obsolete
130-
130+
if (!string.IsNullOrEmpty(automationId))
131+
{
132+
control.AutomationId = automationId;
133+
}
131134
View = new StackLayout
132135
{
133136
Orientation = StackOrientation.Horizontal,
@@ -139,7 +142,7 @@ public ExtendedCell()
139142
}
140143
}
141144

142-
StackLayout CreateListViewTestSection(Type controlType)
145+
StackLayout CreateListViewTestSection(Type controlType,string automationId)
143146
{
144147
var name = controlType.GenericTypeArguments[0].Name;
145148
name = name.Replace("Extended", "", StringComparison.InvariantCultureIgnoreCase);
@@ -152,7 +155,7 @@ StackLayout CreateListViewTestSection(Type controlType)
152155
{
153156
VerticalOptions = LayoutOptions.Start,
154157
ItemsSource = data,
155-
ItemTemplate = new DataTemplate(controlType)
158+
ItemTemplate = new DataTemplate(() => new ExtendedCell<ExtendedEntry>(automationId))
156159
};
157160

158161
button.Clicked += (sender, args) =>
@@ -167,7 +170,7 @@ StackLayout CreateListViewTestSection(Type controlType)
167170
return new StackLayout() { Children = { button, listView } };
168171
}
169172

170-
StackLayout CreateTableViewTestSection<T>() where T : View, IHaveControlFocusedProperty
173+
StackLayout CreateTableViewTestSection<T>(string automationId) where T : View, IHaveControlFocusedProperty
171174
{
172175
var name = typeof(T).Name;
173176
name = name.Replace("Extended", "", StringComparison.InvariantCultureIgnoreCase);
@@ -184,7 +187,7 @@ StackLayout CreateTableViewTestSection<T>() where T : View, IHaveControlFocusedP
184187
var tableRoot = new TableRoot();
185188
var tableSection = new TableSection();
186189

187-
var cell = new ExtendedCell<T>();
190+
var cell = new ExtendedCell<T>(automationId);
188191

189192
cell.BindingContext = data;
190193

@@ -203,11 +206,11 @@ StackLayout CreateTableViewTestSection<T>() where T : View, IHaveControlFocusedP
203206

204207
protected override void Init()
205208
{
206-
var entrySection = CreateListViewTestSection(typeof(ExtendedCell<ExtendedEntry>));
207-
var editorSection = CreateListViewTestSection(typeof(ExtendedCell<ExtendedEditor>));
209+
var entrySection = CreateListViewTestSection(typeof(ExtendedCell<ExtendedEntry>),"EntryListView");
210+
var editorSection = CreateListViewTestSection(typeof(ExtendedCell<ExtendedEditor>), "EditorListView");
208211

209-
var entryTableSection = CreateTableViewTestSection<ExtendedEntry>();
210-
var editorTableSection = CreateTableViewTestSection<ExtendedEditor>();
212+
var entryTableSection = CreateTableViewTestSection<ExtendedEntry>("EntryTable");
213+
var editorTableSection = CreateTableViewTestSection<ExtendedEditor>("EditorTable");
211214

212215
Content = new StackLayout() { Children = { entrySection, editorSection, entryTableSection, editorTableSection } };
213216
}

src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40955.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class Bugzilla40955 : TestFlyoutPage
1919

2020
protected override void Init()
2121
{
22+
// Set FlyoutBehavior to Popover to ensure consistent behavior across desktop and mobile platforms.
23+
// Windows and Catalyst default (FlyoutLayoutBehavior.Default) uses Split mode, which differs from mobile platforms.
24+
FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover;
2225
var masterPage = new MasterPage();
2326
Flyout = masterPage;
2427
masterPage.ListView.ItemSelected += (sender, e) =>
@@ -114,7 +117,8 @@ public _409555_Page1()
114117

115118
var lbl = new Label
116119
{
117-
Text = LabelPage1
120+
Text = LabelPage1,
121+
AutomationId = "LabelOne"
118122
};
119123

120124
lbl.GestureRecognizers.Add(new TapGestureRecognizer
@@ -142,7 +146,8 @@ public _409555_Page2()
142146
Title = Page2Title;
143147
var lbl = new Label
144148
{
145-
Text = LabelPage2
149+
Text = LabelPage2,
150+
AutomationId = "LabelTwo"
146151
};
147152

148153
lbl.GestureRecognizers.Add(new TapGestureRecognizer
@@ -162,7 +167,8 @@ public _409555_Page3()
162167

163168
var lbl = new Label
164169
{
165-
Text = LabelPage3
170+
Text = LabelPage3,
171+
AutomationId = "LabelThree"
166172
};
167173

168174
lbl.GestureRecognizers.Add(new TapGestureRecognizer

src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue12429.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public Issue12429()
1414
InitializeComponent();
1515

1616
// TODO: make this work
17-
//if (DeviceInfo.Platform == DevicePlatform.Android)
18-
// SmallFlyoutItem = SmallFlyoutItem / DeviceDisplay.MainDisplayInfo.Density;
17+
if (DeviceInfo.Platform == DevicePlatform.Android)
18+
SmallFlyoutItem = SmallFlyoutItem / DeviceDisplay.MainDisplayInfo.Density;
1919

20-
//if (DeviceInfo.Platform == DevicePlatform.Android)
21-
// SizeToModifyBy = SizeToModifyBy / DeviceDisplay.MainDisplayInfo.Density;
20+
if (DeviceInfo.Platform == DevicePlatform.Android)
21+
SizeToModifyBy = SizeToModifyBy / DeviceDisplay.MainDisplayInfo.Density;
2222

2323
this.BindingContext = this;
2424
}

src/Controls/tests/TestCases.HostApp/Issues/XFIssue/ShellFlyoutHeaderBehavior.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public ShellFlyoutHeaderBehavior()
1010

1111
protected override void Init()
1212
{
13+
14+
// Lock FlyoutBehavior to keep the flyout open when interacting with menu items, ensuring consistent testing across platforms.
15+
Shell.SetFlyoutBehavior(this, FlyoutBehavior.Locked);
1316
FlyoutHeader = new Grid()
1417
{
1518
HeightRequest = 143,
Lines changed: 38 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Diagnostics;
2-
using NUnit.Framework;
1+
using NUnit.Framework;
32
using UITest.Appium;
43
using UITest.Core;
54

@@ -14,101 +13,40 @@ public Bugzilla31333(TestDevice testDevice) : base(testDevice)
1413

1514
public override string Issue => "Focus() on Entry in ViewCell brings up keyboard, but doesn't have cursor in EditText";
1615

17-
// TODO: Migrating from Xamarin.UITest, some method calls in here
18-
// do not translate to Appium (yet) need to look into that later.
19-
// [FailsOnAndroidWhenRunningOnXamarinUITest]
20-
// [FailsOnIOSWhenRunningOnXamarinUITest]
21-
// [Test]
22-
// #if __MACOS__
23-
// [Ignore("EnterText on UITest.Desktop not implemented")]
24-
// #endif
25-
// //[UiTest(typeof(NavigationPage))]
26-
// public void Issue31333FocusEntryInListViewCell()
27-
// {
28-
// App.Tap("Focus Entry in ListView");
29-
// WaitForFocus();
30-
// App.EnterText("Entry in ListView Success");
31-
// WaitForTextQuery("Entry in ListView Success");
32-
// App.Tap("Focus Entry in ListView");
33-
// }
34-
35-
// [FailsOnAndroid]
36-
// [FailsOnIOSWhenRunningOnXamarinUITest]
37-
// [Test]
38-
// #if __MACOS__
39-
// [Ignore("EnterText on UITest.Desktop not implemented")]
40-
// #endif
41-
// //[UiTest(typeof(NavigationPage))]
42-
// public void Issue31333FocusEditorInListViewCell()
43-
// {
44-
// App.Tap("Focus Editor in ListView");
45-
// WaitForFocus();
46-
// App.EnterText("Editor in ListView Success");
47-
// WaitForTextQuery("Editor in ListView Success");
48-
// App.Tap("Focus Editor in ListView");
49-
// }
50-
51-
52-
// [FailsOnAndroid]
53-
// [FailsOnIOSWhenRunningOnXamarinUITest]
54-
// [Test]
55-
// #if __MACOS__
56-
// [Ignore("EnterText on UITest.Desktop not implemented")]
57-
// #endif
58-
// //[UiTest(typeof(NavigationPage))]
59-
// public void Issue31333FocusEntryInTableViewCell()
60-
// {
61-
// App.Tap("Focus Entry in Table");
62-
// WaitForFocus();
63-
// App.EnterText("Entry in TableView Success");
64-
// WaitForTextQuery("Entry in TableView Success");
65-
// App.Tap("Focus Entry in Table");
66-
// }
67-
68-
// [FailsOnAndroid]
69-
// [FailsOnIOSWhenRunningOnXamarinUITest]
70-
// [Test]
71-
// #if __MACOS__
72-
// [Ignore("EnterText on UITest.Desktop not implemented")]
73-
// #endif
74-
// //[UiTest(typeof(NavigationPage))]
75-
// public void Issue31333FocusEditorInTableViewCell()
76-
// {
77-
// App.Tap("Focus Editor in Table");
78-
// WaitForFocus();
79-
// App.EnterText("Editor in TableView Success");
80-
// WaitForTextQuery("Editor in TableView Success");
81-
// App.Tap("Focus Editor in Table");
82-
// }
83-
84-
// void WaitForFocus()
85-
// {
86-
// Task.Delay(500).Wait();
87-
// }
88-
89-
// void WaitForTextQuery(string text)
90-
// {
91-
// var watch = new Stopwatch();
92-
// watch.Start();
93-
94-
// // 4-5 seconds should be more than enough time to wait for the query to work
95-
// while (watch.ElapsedMilliseconds < 5000)
96-
// {
97-
// // We have to query this way (instead of just using WaitForElement) because
98-
// // WaitForElement on iOS won't find text in Entry or Editor
99-
// // And we can't rely on running this query immediately after entering the text into the control
100-
// // because on Android the query will occasionally fail if it runs too soon after entering the text
101-
// var textQuery = App.Query(query => query.Text(text);
102-
// if (textQuery.Length > 0)
103-
// {
104-
// return;
105-
// }
106-
107-
// Task.Delay(1000).Wait();
108-
// }
109-
110-
// watch.Stop();
111-
112-
// Assert.Fail($"Timed out waiting for text '{text}'");
113-
// }
114-
}
16+
[Test]
17+
public void Issue31333FocusEntryInListViewCell()
18+
{
19+
App.Tap("Focus Entry in ListView");
20+
App.EnterText("EntryListView", "Entry in ListView Success");
21+
Assert.That(App.WaitForElement("EntryListView")?.GetText(), Is.EqualTo("Entry in ListView Success"));
22+
App.Tap("Focus Entry in ListView");
23+
}
24+
25+
[Test]
26+
public void Issue31333FocusEditorInListViewCell()
27+
{
28+
App.Tap("Focus Editor in ListView");
29+
App.EnterText("EditorListView", "Editor in ListView Success");
30+
Assert.That(App.WaitForElement("EditorListView")?.GetText(), Is.EqualTo("Editor in ListView Success"));
31+
App.Tap("Focus Editor in ListView");
32+
}
33+
34+
[Test]
35+
public void Issue31333FocusEntryInTableViewCell()
36+
{
37+
App.Tap("Focus Entry in Table");
38+
App.EnterText("EntryTable", "Entry in TableView Success");
39+
Assert.That(App.WaitForElement("EntryTable")?.GetText(), Is.EqualTo("Entry in TableView Success"));
40+
App.Tap("Focus Entry in Table");
41+
}
42+
#if !IOS //Once Editor text is entered the cursor move to second line when using App.EnterText method in appium which results retrived text is not as expected one.
43+
[Test]
44+
public void Issue31333FocusEditorInTableViewCell()
45+
{
46+
App.Tap("Focus Editor in Table");
47+
App.EnterText("EditorTable", "Editor in TableView Success");
48+
Assert.That(App.WaitForElement("EditorTable")?.GetText(), Is.EqualTo("Editor in TableView Success"));
49+
App.Tap("Focus Editor in Table");
50+
}
51+
#endif
52+
}
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1-
using NUnit.Framework;
1+
#if TEST_FAILS_ON_WINDOWS // On Windows, sometimes destructor calls requires two or more navigation, due to this test fails randomly.
2+
using NUnit.Framework;
23
using UITest.Appium;
34
using UITest.Core;
45

56
namespace Microsoft.Maui.TestCases.Tests.Issues;
67

78
public class Bugzilla40955 : _IssuesUITest
89
{
10+
const string DestructorMessage = "NavigationPageEx Destructor called";
11+
const string LabelPage1 = "LabelOne";
12+
const string LabelPage2 = "LabelTwo";
13+
const string LabelPage3 = "LabelThree";
14+
15+
const string Page1Title = "Page1";
16+
const string Page2Title = "Page2";
17+
const string Page3Title = "Page3";
18+
919
public Bugzilla40955(TestDevice testDevice) : base(testDevice)
1020
{
1121
}
1222

1323
public override string Issue => "Memory leak with FormsAppCompatActivity and NavigationPage";
1424

15-
// TODO from Xamarin.UITest migration
16-
// Needs some refactoring to use AutomationIds
17-
// [Test]
18-
// [Category(UITestCategories.Performance)]
19-
// public void MemoryLeakInFormsAppCompatActivity()
20-
// {
21-
// App.WaitForElement(Page1Title);
22-
// App.Tap(LabelPage1);
23-
// App.WaitForElement(Page1Title);
24-
// App.Tap(Page2Title);
25-
// App.WaitForElement(LabelPage2);
26-
// App.Tap(LabelPage2);
27-
// App.WaitForElement(Page2Title);
28-
// App.Tap(Page3Title);
29-
// App.WaitForElement(LabelPage3);
30-
// App.Tap(LabelPage3);
31-
// App.WaitForElement(Success);
32-
// }
33-
}
25+
[Test]
26+
[Category(UITestCategories.Performance)]
27+
public void MemoryLeakInFormsAppCompatActivity()
28+
{
29+
App.WaitForElement(Page1Title);
30+
App.WaitForElement(LabelPage1);
31+
App.Tap(LabelPage1);
32+
App.WaitForElement(Page2Title);
33+
App.Tap(Page2Title);
34+
App.WaitForElement(LabelPage2);
35+
App.Tap(LabelPage2);
36+
App.WaitForElement(Page3Title);
37+
App.Tap(Page3Title);
38+
App.WaitForElement(LabelPage3);
39+
App.Tap(LabelPage3);
40+
App.WaitForElement(DestructorMessage);
41+
}
42+
}
43+
#endif

0 commit comments

Comments
 (0)