Skip to content

Commit 19705bd

Browse files
NirmalKumarYuvarajPureWeen
authored andcommitted
Re-enabled flaky UI test TextInEditorShouldScroll (#29167)
* Fixed flaky editor test * Added scroll down again to double check * Optimized code changes and added new test snapshots * Added missing WinUI snap
1 parent a93d609 commit 19705bd

File tree

7 files changed

+102
-49
lines changed

7 files changed

+102
-49
lines changed
6.86 KB
Loading
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#if MACCATALYST
2+
using UIKit;
3+
using Microsoft.Maui.Platform;
4+
#endif
5+
6+
namespace Maui.Controls.Sample.Issues;
7+
8+
[Issue(IssueTracker.Github, 19500, "[iOS] Editor is not be able to scroll if IsReadOnly is true", PlatformAffected.iOS)]
9+
public partial class Issue19500 : TestContentPage
10+
{
11+
const string BaseEditorText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla porttitor mauris non ornare ultrices. Ut semper ultrices justo eget semper.Ut imperdiet dolor ut vestibulum molestie. Duis a libero ex. Etiam mi urna, lobortis sed tincidunt in, tempus eget magna. Aenean quis malesuada eros. Phasellus felis eros, condimentum et tortor sed, condimentum convallis turpis. Sed in varius metus, at auctor orci. Maecenas luctus nibh nibh, nec aliquam est fermentum in. Etiam consectetur lectus erat, sed placerat sapien rutrum eu. Suspendisse tincidunt fermentum tempor.Maecenas egestas neque nec lacinia fringilla.";
12+
13+
protected override void Init()
14+
{
15+
var rootLayout = new VerticalStackLayout
16+
{
17+
Spacing = 10,
18+
Padding = 10
19+
};
20+
21+
var descriptionLabel = CreateLabel(
22+
"This test case is to verify that the Editor is scrollable when IsReadOnly is set to true.",
23+
"descriptionLabel");
24+
25+
var yPositionLabel = CreateLabel("0", "yPositionLabel");
26+
27+
var editor = CreateEditor(yPositionLabel);
28+
29+
rootLayout.Children.Add(descriptionLabel);
30+
rootLayout.Children.Add(editor);
31+
rootLayout.Children.Add(yPositionLabel);
32+
33+
Content = rootLayout;
34+
}
35+
36+
Label CreateLabel(string text, string automationId) =>
37+
new Label
38+
{
39+
Text = text,
40+
AutomationId = automationId
41+
};
42+
43+
Editor CreateEditor(Label yPositionLabel)
44+
{
45+
var editor = new Editor
46+
{
47+
HeightRequest = 100,
48+
IsReadOnly = true,
49+
AutomationId = "editor",
50+
Text = GetEditorText()
51+
};
52+
53+
#if MACCATALYST
54+
editor.HandlerChanged += (_, _) =>
55+
{
56+
if (editor.Handler?.PlatformView is MauiTextView mauiTextView)
57+
{
58+
mauiTextView.Scrolled += (s, e) =>
59+
{
60+
if (s is UIScrollView scrollView)
61+
{
62+
yPositionLabel.Text = scrollView.ContentOffset.Y.ToString();
63+
}
64+
};
65+
}
66+
};
67+
#endif
68+
69+
return editor;
70+
}
71+
72+
private string GetEditorText()
73+
{
74+
#if MACCATALYST
75+
return BaseEditorText + " " + BaseEditorText;
76+
#else
77+
return BaseEditorText;
78+
#endif
79+
}
80+
}

src/Controls/tests/TestCases.HostApp/Issues/Issue19500.xaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Controls/tests/TestCases.HostApp/Issues/Issue19500.xaml.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
#if TEST_FAILS_ON_CATALYST // Since this test verifies the scrolling behavior in the editor control and the App.ScrollDown function is inconsistent, relying on screenshot verification causes flakiness in CI. It needs to be validated using an alternative approach, or else it would be better to consider this for manual testing.
2-
// Issue for reenable: https://github.com/dotnet/maui/issues/29025
31
using NUnit.Framework;
42
using UITest.Appium;
53
using UITest.Core;
64

7-
namespace Microsoft.Maui.TestCases.Tests.Issues
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue19500 : _IssuesUITest
87
{
9-
public class Issue19500 : _IssuesUITest
10-
{
11-
public override string Issue => "[iOS] Editor is not be able to scroll if IsReadOnly is true";
8+
public override string Issue => "[iOS] Editor is not be able to scroll if IsReadOnly is true";
129

13-
public Issue19500(TestDevice device) : base(device)
14-
{
15-
}
10+
const string yPositionLabel = "yPositionLabel";
1611

17-
[Test]
18-
[Category(UITestCategories.Editor)]
19-
public void TextInEditorShouldScroll()
20-
{
21-
_ = App.WaitForElement("editor");
22-
App.ScrollDown("editor");
12+
public Issue19500(TestDevice device) : base(device)
13+
{
14+
}
2315

24-
// The test passes if the text inside the editor scrolls down
25-
VerifyScreenshot();
26-
}
16+
[Test]
17+
[Category(UITestCategories.Editor)]
18+
public void TextInEditorShouldScroll()
19+
{
20+
var yPosLabel = App.WaitForElement(yPositionLabel);
21+
App.ScrollDown("editor");
22+
#if MACCATALYST
23+
App.ScrollDown("editor"); // To make sure the editor is scrolled down
24+
var yPos = yPosLabel.GetText();
25+
Assert.That(yPos,Is.GreaterThan("0")); // The Y position should be greater than 0 after scrolling down
26+
#else
27+
// The test passes if the text inside the editor scrolls down
28+
VerifyScreenshot();
29+
#endif
2730
}
28-
}
29-
#endif
31+
}
2.52 KB
Loading
7.65 KB
Loading

0 commit comments

Comments
 (0)