Skip to content

Commit

Permalink
[Testing] Enabling ported UITests from Xamarin.UITests to Appium - 65 (
Browse files Browse the repository at this point in the history
…#26873)

* migrated issue fron xamarian uitest into appium

* migrated issue

* Migrated the Bugzilla37625 (#56)

Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>

* Updated Enabled UITests

* Fixed flaky tests Issue1414

* Update Issue7290.cs

* Update Issue5412.cs

* Update Bugzilla30317.cs

---------

Co-authored-by: LogishaSelvarajSF4525 <logisha.selvaraj@syncfusion.com>
Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>
  • Loading branch information
3 people authored Dec 31, 2024
1 parent 07cc973 commit 2f51dd9
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ protected override async void Init()
int retry = 5;
while (retry-- >= 0)
{
var imageUri = new Uri("https://raw.githubusercontent.com/xamarin/Xamarin.Forms/main/Microsoft.Maui.Controls.ControlGallery.Android/Assets/WebImages/XamarinLogo.png");
Content = new Image() { Source = new UriImageSource() { Uri = imageUri }, BackgroundColor = Colors.Black, AutomationId = "success" };
var imageUri = new Uri("https://raw.githubusercontent.com/dotnet/maui/main/src/Compatibility/ControlGallery/src/Android/Resources/drawable/coffee.png");
Content = new Image() { Source = new UriImageSource() { Uri = imageUri }, BackgroundColor = Colors.Beige, AutomationId = "success" };

await Task.Delay(50);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,16 @@ public class Bugzilla45125 : TestContentPage
const string DisappearingLabelId = "disappearing";
const string TestButtonId = "TestButtonId";

static int _Appearing = 0;
static int _Disappearing = 0;
int _Appearing = 0;
int _Disappearing = 0;

static Label _status = new Label
{
TextColor = Colors.White,
//TODO: NoWrap causes the Label to be missing from the Horizontal StackLayout
//LineBreakMode = LineBreakMode.NoWrap
};

static Label _groupsAppearing = new Label
{
TextColor = Colors.Green,
AutomationId = AppearingLabelId
};
Label _status;

static Label _groupsDisappearing = new Label
{
TextColor = Colors.Blue,
AutomationId = DisappearingLabelId
};
Label _groupsAppearing;

static ScrollView _scroll = new ScrollView
{
BackgroundColor = Colors.Black,
Content = _status,
MinimumWidthRequest = 200
};
Label _groupsDisappearing;

ScrollView _scroll;

class GroupItem
{
Expand Down Expand Up @@ -78,13 +59,43 @@ public HeaderCell()

protected override void Init()
{
InitializeControls();

_status.Text = _groupsAppearing.Text = _groupsDisappearing.Text = "";
_Appearing = _Disappearing = 0;
_scroll.SetScrolledPosition(0, 0);

InitTest(ListViewCachingStrategy.RecycleElement, true);
}

void InitializeControls(){

_status = new Label
{
TextColor = Colors.White
};

_groupsAppearing = new Label
{
TextColor = Colors.Green,
AutomationId = AppearingLabelId
};

_groupsDisappearing = new Label
{
TextColor = Colors.Blue,
AutomationId = DisappearingLabelId
};

_scroll = new ScrollView
{
BackgroundColor = Colors.Black,
Content = _status,
WidthRequest = 200,
HeightRequest = 500
};
}

void InitTest(ListViewCachingStrategy cachingStrategy, bool useTemplate)
{
List<GroupedData> groups = GetGroups();
Expand All @@ -94,6 +105,8 @@ void InitTest(ListViewCachingStrategy cachingStrategy, bool useTemplate)
ItemsSource = groups,
ItemTemplate = new DataTemplate(typeof(MyCell)),
HasUnevenRows = true,
HeightRequest = 500,
WidthRequest = 200,

// Must be grouped to repro
IsGroupingEnabled = true
Expand All @@ -108,16 +121,18 @@ void InitTest(ListViewCachingStrategy cachingStrategy, bool useTemplate)
listView.ItemAppearing += ListView_ItemAppearing;
listView.ItemDisappearing += ListView_ItemDisappearing;

var horStack = new StackLayout
InitializeControls();

var horStack = new HorizontalStackLayout
{
Orientation = StackOrientation.Horizontal,
Children = { _scroll, listView },
HeightRequest = 300
HeightRequest = 500
};
horStack.Children.Add(_scroll);
horStack.Children.Add(listView);

Button nextButton = new Button { Text = "Next", AutomationId = TestButtonId };
nextButton.Clicked += NextButton_Clicked;
StackLayout stack = new StackLayout
VerticalStackLayout stack = new VerticalStackLayout
{
Children = { new Label { Text = Instructions }, _groupsAppearing, _groupsDisappearing, horStack, nextButton }
};
Expand Down
85 changes: 26 additions & 59 deletions src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue5412.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 5412, "5412 - (NavigationBar disappears on FlyoutPage)", PlatformAffected.UWP)]
Expand Down Expand Up @@ -40,78 +38,47 @@ public class Issue5412SettingPage : ContentPage
{
public Issue5412SettingPage()
{
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete

Content = new StackLayout
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children = {
//new Label
//{
// Text = "Settings Page",
// FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label))
//},
//new Label
//{
// Text = "Navigate back and check the navbar & menu are still visible.",
// FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label))
//},
new Label
{
Text = "Settings Page",
FontSize = 22
},
new Label
{
Text = "Navigate back and check the navbar & menu are still visible.",
FontSize = 16
},
}
};
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
}
};

public class Issue5412IndexPage : ContentPage
{
public Issue5412IndexPage()
{
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
Content = new StackLayout
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children = {
//new Label
//{
// Text = "Index Page",
// FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label))
//},
//new Label
//{
// Text = "Open the hamburger menu and navigate to settings page",
// FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label))
//},
new Label
{
Text = "Index Page",
FontSize = 22
},
new Label
{
Text = "Open the hamburger menu and navigate to settings page",
FontSize = 16
},
}
};
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public Bugzilla30317(TestDevice testDevice) : base(testDevice)
{
}

protected override bool ResetAfterEachTest => true;

public override string Issue => "https://bugzilla.xamarin.com/show_bug.cgi?id=30137";

[Test, Order(1)]
[Test]
public void Bugzilla30317ItemSourceOnAppearingContentPage()
{
App.WaitForElement(PageOne);
Expand All @@ -56,12 +58,12 @@ public void Bugzilla30317ItemSourceOnAppearingContentPage()
TouchAndHold(PageOneItem5);
}

[Test, Order(2)]
[Test]
public void Bugzilla30317ItemSourceCtorContentPage()
{
App.WaitForElement(PageTwoButton);
App.Tap(PageTwoButton);
App.WaitForElement(PageTwo);
App.WaitForElementTillPageNavigationSettled(PageTwo);

App.WaitForElement(PageTwoItem1);
TouchAndHold(PageTwoItem1);
Expand All @@ -70,18 +72,21 @@ public void Bugzilla30317ItemSourceCtorContentPage()
TouchAndHold(PageTwoItem5);
}

[Test, Order(3)]
[Test]
public void Bugzilla30317ItemSourceTabbedPage()
{

App.WaitForElement(PageTwoButton);
App.Tap(PageTwoButton);
App.WaitForElementTillPageNavigationSettled(PageTwo);

App.WaitForElement(PageTwo);
App.WaitForElement(PageThreeButton);
App.Tap(PageThreeButton);

App.WaitForElement(TabTwo);
App.WaitForElementTillPageNavigationSettled(TabTwo);
App.Tap(TabTwo);

App.WaitForElement(TabTwoItem1);
App.WaitForElementTillPageNavigationSettled(TabTwoItem1);
TouchAndHold(TabTwoItem1);
App.WaitForElement(TabTwoItem1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if WINDOWS
using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -15,11 +14,9 @@ public Bugzilla37625(TestDevice testDevice) : base(testDevice)

[Test]
[Category(UITestCategories.Image)]
[Category(UITestCategories.Compatibility)]
public void Bugzilla37625Test()
{
App.WaitForElement("success");
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,38 @@ public class Bugzilla45125 : _IssuesUITest
{
const string AppearingLabelId = "appearing";
const string DisappearingLabelId = "disappearing";
const string TestButtonId = "TestButtonId";
const string TestButtonId = "Next";

public Bugzilla45125(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "ListView lacks a way to get information about visible elements (such as FirstVisibleItem) to restore visual positions of elements";

// TODO From Xamarin.UITest migration: test references variable in UI, needs to be refactored
// [FailsOnAndroidWhenRunningOnXamarinUITest]
// [FailsOnIOSWhenRunningOnXamarinUITest]
// [Test]
// public void Bugzilla45125Test()
// {
// RunTest();

// App.Tap(TestButtonId);
// RunTest();
[Test]
[Category(UITestCategories.ListView)]
public void Bugzilla45125Test()
{
RunTest();

// App.Tap(TestButtonId);
// RunTest();
App.Tap(TestButtonId);
RunTest();

// App.Tap(TestButtonId);
// RunTest();
// }
App.Tap(TestButtonId);
RunTest();

// void RunTest()
// {
// App.WaitForElement(AppearingLabelId);
// App.WaitForElement(DisappearingLabelId);
App.Tap(TestButtonId);
RunTest();
}

// App.Screenshot("There should be appearing and disappearing events for the Groups and Items.");
// var appearing = int.Parse(App.FindElement(AppearingLabelId)?.GetText() ?? "0");
// var disappearing = int.Parse(App.FindElement(DisappearingLabelId)?.GetText() ?? "0");
void RunTest()
{
App.WaitForElementTillPageNavigationSettled(AppearingLabelId);
App.WaitForElementTillPageNavigationSettled(DisappearingLabelId);
var appearing = int.Parse(App.FindElement(AppearingLabelId)?.GetText() ?? "0");
var disappearing = int.Parse(App.FindElement(DisappearingLabelId)?.GetText() ?? "0");

// Assert.That(appearing, Is.GreaterThan(0), $"Test {_TestNumber}: No appearing events for groups found.");
// Assert.That(disappearing, Is.GreaterThan(0), $"Test {_TestNumber}: No disappearing events for groups found.");
// }
Assert.That(appearing, Is.GreaterThan(0));
Assert.That(disappearing, Is.GreaterThan(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public void InvalidCastExceptionWhenScrollingAndRefreshingTableView()
{
App.WaitForElement("TableView");
App.ScrollDown("TableView", ScrollStrategy.Gesture, 1.0, 50);
App.WaitForElement("Cell 4-24");
App.WaitForAnyElement(["Cell 4-24","Cell 0-24"]);
App.ScrollUp("TableView", ScrollStrategy.Gesture, 1.0, 30);
App.WaitForElement("Cell 0-0");
App.WaitForAnyElement(["Cell 0-0","Cell 3-24"]);
}
}
#endif
Loading

0 comments on commit 2f51dd9

Please sign in to comment.