Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Enabling ported UITests from Xamarin.UITests to Appium - 61 #26761

Merged
merged 16 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ protected override void Init()

var sc = new SwitchCell
{
Text = "Toggle switch; nothing should crash"
Text = "Toggle switch; nothing should crash",
AutomationId = "Switch"
};

var button = new Button();
var button = new Button
{
AutomationId = "Button"
};
button.SetBinding(Button.TextProperty, new Binding("On", source: sc));

var vc = new ViewCell
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Maui.Layouts;
namespace Maui.Controls.Sample.Issues;


Expand Down Expand Up @@ -30,8 +31,11 @@ protected override void Init()
Color = Colors.Black,
AutomationId = Black
};

mainLayout.Children.Add(view);
AbsoluteLayout.SetLayoutBounds(view, new Rect(0, 0, 1, 1));
AbsoluteLayout.SetLayoutFlags(view, AbsoluteLayoutFlags.All);

mainLayout.Add(view);
Content = thePage;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public Bugzilla41415()
var grid = new Grid
{
BackgroundColor = Colors.Yellow,
WidthRequest = 1000,
HeightRequest = 1000,
// To make this test works for desktop apps, we need to set a big size for the grid
WidthRequest = 3000,
HeightRequest = 3000,
Children =
{
new BoxView
{
WidthRequest = 200,
HeightRequest = 200,
WidthRequest = 2200,
HeightRequest = 2200,
BackgroundColor = Colors.Red,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
Expand Down Expand Up @@ -82,7 +83,34 @@ public Bugzilla41415()
_x = 100;
};

Content = new StackLayout { Children = { button, labelx, labely, labelz, labela, scrollView } };
Grid.SetRow(button, 0);
Grid.SetRow(labelx, 1);
Grid.SetRow(labely, 2);
Grid.SetRow(labelz, 3);
Grid.SetRow(labela, 4);
Grid.SetRow(scrollView, 5);

Content = new Grid
{
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star },
},
Children =
{
button,
labelx,
labely,
labelz,
labela,
scrollView,
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected override void Init()
{
Title = "Flyout",
BackgroundColor = Colors.SkyBlue,
IconImageSource = "menuIcon",
IconImageSource = "menu_icon",
Content = new StackLayout()
{
Children =
Expand Down
83 changes: 41 additions & 42 deletions src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue5132.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ protected override void Init()
Title = "Shell";
FlyoutIcon = new FontImageSource
{
Glyph = "\uf2fb",
FontFamily = DefaultFontFamily(),
Glyph = "\uf224",
FontFamily = "Ion",
Size = 20,
AutomationId = _idIconElement
};
#pragma warning disable CS0618 // Type or member is obsolete
FlyoutIcon.SetValue(AutomationProperties.HelpTextProperty, "This as Shell FlyoutIcon");
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
FlyoutIcon.SetValue(AutomationProperties.NameProperty, "Shell Icon");
#pragma warning restore CS0618 // Type or member is obsolete

FlyoutIcon.SetValue(SemanticProperties.HintProperty, "This as Shell FlyoutIcon");

FlyoutIcon.SetValue(SemanticProperties.DescriptionProperty, "Shell Icon");

Items.Add(new FlyoutItem
{
Title = _titleElement,
Expand All @@ -34,39 +33,39 @@ protected override void Init()
});
}

static string DefaultFontFamily()
{
var fontFamily = "";
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
#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
switch (Device.RuntimePlatform)
{
case Device.iOS:
fontFamily = "Ionicons";
break;
case Device.WinUI:
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
break;
case Device.Android:
default:
fontFamily = "fonts/ionicons.ttf#";
break;
}
#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
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
// static string DefaultFontFamily()
// {
// var fontFamily = "";
// #pragma warning disable CS0618 // Type or member is obsolete
// #pragma warning disable CS0618 // Type or member is obsolete
// #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
// switch (Device.RuntimePlatform)
// {
// case Device.iOS:
// fontFamily = "Ionicons";
// break;
// case Device.WinUI:
// fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
// break;
// case Device.Android:
// default:
// fontFamily = "fonts/ionicons.ttf#";
// break;
// }
// #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
// #pragma warning restore CS0618 // Type or member is obsolete
// #pragma warning restore CS0618 // Type or member is obsolete

return fontFamily;
}
// return fontFamily;
// }
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS //Unable to access the switch element directly when it placed inside the TableView, Also Hardcoded TapCoordinates don't work reliably in CI environments for desktop platforms.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -12,17 +13,23 @@ public Bugzilla36955(TestDevice testDevice) : base(testDevice)

public override string Issue => "[iOS] ViewCellRenderer.UpdateIsEnabled referencing null object";

// TODO from Xamarin.UITest Migration, seems to be ignored already
// Also uses some specific XamUITest APIs that we need to find counterparts for
// [Ignore("Test failing due to unrelated issue, disable for moment")]
// [Category(UITestCategories.TableView)]
// [Test]
// public void Bugzilla36955Test()
// {
// AppResult[] buttonFalse = App.Query(q => q.Button().Text("False"));
// Assert.AreEqual(buttonFalse.Length == 1, true);
// App.Tap(q => q.Class("Switch"));
// AppResult[] buttonTrue = App.Query(q => q.Button().Text("True"));
// Assert.AreEqual(buttonTrue.Length == 1, true);
// }
}
[Category(UITestCategories.TableView)]
[Test]
public void Bugzilla36955Test()
{
App.WaitForElement("Button");
Assert.That(App.FindElement("Button").GetText(), Is.EqualTo("False"));

ToggleSwitch();
Assert.That(App.FindElement("Button").GetText(), Is.EqualTo("True"));
}
void ToggleSwitch()
{
#if ANDROID
App.TapCoordinates(1000, 100);
#elif IOS
App.Tap(AppiumQuery.ByXPath("//XCUIElementTypeSwitch[@name='Toggle switch; nothing should crash']"));
#endif
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Bugzilla40092 : _IssuesUITest
{

#if MACCATALYST
const string Ok = "action-button--999";
#else
const string Ok = "Ok";
#endif

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

public override string Issue => "Ensure android devices with fractional scale factors (3.5) don't have a white line around the border";

// TODO: From Xamarin.UITest migration.
// Does some advanced commands to determine layouts, need to find the equivalent on Appium
// [Test]
// [Category(UITestCategories.BoxView)]
// public void AllScreenIsBlack()
// {
// App.WaitForElement(Ok);
// App.Tap(Ok);
// var box = App.WaitForElement(Black)[0];
// var layout = App.WaitForElement(White)[0];

// var assert = box.Rect.Height == layout.Rect.Height &&
// box.Rect.Width == layout.Rect.Width;

// Assert.IsTrue(assert);
// }
[Test]
[Category(UITestCategories.BoxView)]
public void AllScreenIsBlack()
{
#if !ANDROID // Display alert not shown in android also this is not a needed one for ensuring this case, so ignored the below steps on Android.
App.WaitForElement(Ok);
App.Tap(Ok);
#else
App.WaitForElement("black");
#endif
VerifyScreenshot();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if !IOS
#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS
// On Android ScrollY and ScrollX values are resetted, Issue: https://github.com/dotnet/maui/issues/26747
// On Windows tests are failing in CI, but not locally. Need to investigate more.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
Expand All @@ -18,25 +20,22 @@ public Bugzilla41415UITests(TestDevice device)

public override string Issue => "ScrollX and ScrollY values are not consistent with iOS";

// Bugzilla41415 (src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla41415.cs)
[Test]
[FailsOnIOSWhenRunningOnXamarinUITest("This test is failing, likely due to product issue")]
[FailsOnMacWhenRunningOnXamarinUITest("This test is failing, likely due to product issue")]
public void Bugzilla41415Test()
{
// This test is failing, likely due to product issue

App.WaitForElement(ButtonId);
App.Tap(ButtonId);
App.WaitForNoElement("x: 100");
App.WaitForNoElement("y: 100");
App.WaitForNoElement("z: True", timeout: TimeSpan.FromSeconds(25));
App.WaitForNoElement("a: True");
App.WaitForElement(ButtonId);
App.WaitForElementTillPageNavigationSettled("x: 100");
App.WaitForElementTillPageNavigationSettled("y: 100");
App.WaitForElement("z: True");
App.WaitForElement("a: True");
App.Tap(ButtonId);
App.WaitForNoElement("x: 200");
App.WaitForNoElement("y: 100");
App.WaitForNoElement("z: True", timeout: TimeSpan.FromSeconds(25));
App.WaitForNoElement("a: False");
App.WaitForElement(ButtonId);
App.WaitForElementTillPageNavigationSettled("y: 100");
App.WaitForElement("z: True");
App.WaitForElement("a: False");
App.WaitForElementTillPageNavigationSettled("x: 200");
}
}
}
Expand Down
Loading
Loading