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 ContextMenu UITests from Xamarin.UITests to Appium - 2 #27405

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ protected override void Init()
AutomationId = "coffee.png"
});

var box = new BoxView
var label = new Label
{
WidthRequest = 30,
HeightRequest = 30,
Color = Colors.Red,
AutomationId = "ColorBox"
Text = "Tap label",
AutomationId = "labelId"
};

var gr = new TapGestureRecognizer();
gr.Command = new Command(() =>
{
box.Color = box.Color == Colors.Red ? Colors.Yellow : Colors.Red;
label.Text = label.Text == "Tap label" ? "Success" : "Tap label";
});
box.GestureRecognizers.Add(gr);
label.GestureRecognizers.Add(gr);
cells.View = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Expand All @@ -46,9 +44,11 @@ protected override void Init()
new Label()
{
Text = "Right click on any item within viewcell (including this label) should trigger context action on this row and you should see a coffee cup. Tap on colored box should change box color",
AutomationId = "ListViewItem"
AutomationId = "ListViewItem",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.FillAndExpand
},
box
label
}
};

Expand Down
172 changes: 147 additions & 25 deletions src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue4314.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,147 @@
//using Microsoft.Maui.Controls.CustomAttributes;
//using Microsoft.Maui.Controls.Internals;

//namespace Maui.Controls.Sample.Issues;

//[Issue(IssueTracker.Github, 4314, "When ListView items is removed and it is empty, Xamarin Forms crash", PlatformAffected.iOS)]
//public class Issue4314 : TestNavigationPage
//{
// const string Success = "Success";

// MessagesViewModel viewModel;
// protected override void Init()
// {
// var page = new ContextActionsGallery(false, true, 2) { Title = "Swipe and delete both" };
// viewModel = page.BindingContext as MessagesViewModel;
// viewModel.Messages.CollectionChanged += (s, e) =>
// {
// if (viewModel.Messages.Count == 0)
// {
// Navigation.PushAsync(new ContentPage { Title = "Success", Content = new Label { Text = Success } });
// }
// };
// Navigation.PushAsync(page);
// }
//}
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 4314, "When ListView items is removed and it is empty, Xamarin Forms crash", PlatformAffected.iOS)]
public class Issue4314 : TestNavigationPage
{
const string Success = "Success";

MessagesViewModel viewModel;
protected override void Init()
{
var page = new ContextActionsGallery(false, true, 2) { Title = "Swipe and delete both" };
viewModel = page.BindingContext as MessagesViewModel;
viewModel.Messages.CollectionChanged += (s, e) =>
{
if (viewModel.Messages.Count == 0)
{
Navigation.PushAsync(new ContentPage { Title = "Success", Content = new Label { Text = Success } });
}
};
Navigation.PushAsync(page);
}
}

internal class MessagesViewModel : ViewModelBase
{
public MessagesViewModel(int messagesCount)
{
Messages = new ObservableCollection<MessageViewModel>(Enumerable.Range(0, messagesCount).Select(i =>
{
return new MessageViewModel { Subject = "Subject Line " + i, MessagePreview = "Lorem ipsum dolorem monkeys bonkers " + i };
}));

MessagingCenter.Subscribe<MessageViewModel, MessageViewModel>(this, "DeleteMessage", (vm, vm2) =>
{
Messages.Remove(vm);
});
}

public ObservableCollection<MessageViewModel> Messages
{
get;
private set;
}
}

[Preserve(AllMembers = true)]
public class MessageViewModel : ViewModelBase
{
public MessageViewModel()
{
Delete = new Command(() => MessagingCenter.Send(this, "DeleteMessage", this));
Move = new Command(() => MessagingCenter.Send(this, "MoveMessage", this));
}

public string Subject
{
get;
set;
}

public string MessagePreview
{
get;
set;
}

public ICommand Delete
{
get;
private set;
}

public ICommand Move
{
get;
private set;
}
}

internal class ContextActionsGallery : ContentPage
{
class MessageCell : TextCell
{
public MessageCell()
{
this.SetBinding(TextProperty, "Subject");
this.SetBinding(DetailProperty, "MessagePreview");

var delete = new MenuItem { Text = "Delete", IsDestructive = true };
delete.SetBinding(MenuItem.CommandProperty, "Delete");

var mark = new MenuItem { Text = "Mark", IconImageSource = "calculator.png" };
var move = new MenuItem { Text = "Move" };

//move.Clicked += async (sender, e) => await Navigation.PopAsync();

ContextActions.Add(mark);
ContextActions.Add(delete);
ContextActions.Add(move);

var clear = new MenuItem { Text = "Clear Items" };
clear.Clicked += (sender, args) => ContextActions.Clear();
ContextActions.Add(clear);
}
}

public ContextActionsGallery(bool tableView = false, bool hasUnevenRows = false, int messagesCount = 100)
{
BindingContext = new MessagesViewModel(messagesCount);

View list;
if (!tableView)
{
list = new ListView
{
HasUnevenRows = hasUnevenRows
};
list.SetBinding(ListView.ItemsSourceProperty, "Messages");
((ListView)list).ItemTemplate = new DataTemplate(typeof(MessageCell));
}
else
{
var section = new TableSection();
section.Add(new TextCell { Text = "I have no ContextActions", Detail = "Sup" });
foreach (var msg in ((MessagesViewModel)BindingContext).Messages)
{
section.Add(new MessageCell { BindingContext = msg });
}

list = new TableView();
((TableView)list).Root = new TableRoot { section };
}

Content = new StackLayout
{
Children = {
new Label { Text = "Email" },
list
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NUnit.Framework;
#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms.
//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -12,23 +14,20 @@ public Bugzilla31330(TestDevice testDevice) : base(testDevice)

public override string Issue => "Disabled context actions appear enabled";

// TODO: porting over from Xamarin.UITest
// We don't seem to have "ActivateContextMenu" (yet)?
// [FailsOnAndroidWhenRunningOnXamarinUITest]
// [FailsOnIOSWhenRunningOnXamarinUITest]
// [Test]
//[Category(UITestCategories.ListView)]
// public void Bugzilla31330Test()
// {
// App.WaitForElement("Something 2");
// App.ActivateContextMenu("Something 1");
// App.WaitForElement("Delete");
// App.Tap("Delete");
// App.DismissContextMenu();
// App.Tap("Something 2");
// App.ActivateContextMenu("Something 2");
// App.WaitForElement("Delete");
// App.Tap("Delete");
// App.WaitForNoElement("Something 2");
// }
}
[Test]
[Category(UITestCategories.ListView)]
public void Bugzilla31330Test()
{
App.WaitForElement("Something 2");
App.ActivateContextMenu("Something 1");
App.WaitForElement("Delete");
App.Tap("Delete");
App.DismissContextMenu();
App.Tap("Something 2");
App.ActivateContextMenu("Something 2");
App.WaitForElement("Delete");
App.Tap("Delete");
App.WaitForNoElement("Something 2");
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using NUnit.Framework;
#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms.
//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Bugzilla57317 : _IssuesUITest
{
const string Success = "Success";
const string BtnAdd = "btnAdd";

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

public override string Issue => "Modifying Cell.ContextActions can crash on Android";

// [Test]
// [Category(UITestCategories.TableView)]
// [FailsOnIOSWhenRunningOnXamarinUITest]
// public void Bugzilla57317Test()
// {
// App.WaitForFirstElement("Cell");
[Test]
[Category(UITestCategories.TableView)]
public void Bugzilla57317Test()
{
App.WaitForFirstElement("Cell");

// App.ActivateContextMenu("Cell");
App.ActivateContextMenu("Cell");

// App.WaitForFirstElement("Self-Deleting item");
// App.Tap(c => c.Marked("Self-Deleting item"));
// }
}
App.WaitForFirstElement("Self-Deleting item");
App.Tap("Self-Deleting item");
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NUnit.Framework;
#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms.
//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -12,35 +14,28 @@ public Bugzilla58833(TestDevice testDevice) : base(testDevice)

public override string Issue => "ListView SelectedItem Binding does not fire";

// [Test]
// [Category(UITestCategories.ListView)]
// [Ignore("Failing without explanation on XTC, please run manually")]
// public void Bugzilla58833Test()
// {
// // Item #1 should not have a tap gesture, so it should be selectable
// App.WaitForElement(q => q.Marked("Item #1"));
// App.Tap(q => q.Marked("Item #1"));
// App.WaitForElement(q => q.Marked(ItemSelectedSuccess));

// // Item #2 should have a tap gesture
// App.WaitForElement(q => q.Marked("Item #2"));
// App.Tap(q => q.Marked("Item #2"));
// App.WaitForElement(q => q.Marked(TapGestureSucess));

// // Both items should allow access to the context menu
// App.ActivateContextMenu("Item #2");
// App.WaitForElement("2 Action");
// #if __ANDROID__
// App.Back();
// #else
// App.Tap(q => q.Marked("Item #3"));


// App.ActivateContextMenu("Item #1");
// App.WaitForElement("1 Action");
// #if __ANDROID__
// App.Back();
// #else
// App.Tap(q => q.Marked("Item #3"));
// }
}
[Test]
[Category(UITestCategories.ListView)]
public void Bugzilla58833Test()
{
// Item #1 should not have a tap gesture, so it should be selectable
App.WaitForElement("Item #1");
App.Tap("Item #1");
App.WaitForElement("ItemSelected Success");

// Item #2 should have a tap gesture
App.WaitForElement("Item #2");
App.Tap("Item #2");
App.WaitForElement("TapGesture Fired");

// Both items should allow access to the context menu
App.ActivateContextMenu("Item #2");
App.WaitForElement("2 Action");
App.DismissContextMenu();

App.ActivateContextMenu("Item #1");
App.WaitForElement("1 Action");
App.DismissContextMenu();
}
}
#endif
Loading
Loading