Added UI test to B45027 (#4079)
authorIone Souza Junior <junior@ionixjunior.com.br>
Tue, 23 Oct 2018 23:33:17 +0000 (20:33 -0300)
committerShane Neuville <shane94@hotmail.com>
Tue, 23 Oct 2018 23:33:17 +0000 (17:33 -0600)
* Add UI test to B45027

* Changed execution of current UI test to Android platform

* Added iOS UI test to B45027

* Refactored UI test execution

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45027.cs

index 260967b..fbfc268 100644 (file)
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System.Linq;
+using System.Collections.Generic;
 using Xamarin.Forms.CustomAttributes;
 using Xamarin.Forms.Internals;
 
@@ -13,12 +14,27 @@ namespace Xamarin.Forms.Controls.Issues
        [Issue(IssueTracker.Bugzilla, 45027, "App crashes when double tapping on ToolbarItem or MenuItem very quickly", PlatformAffected.Android)]
        public class Bugzilla45027 : TestContentPage // or TestMasterDetailPage, etc ...
        {
-               protected override void Init()
+               const string BUTTON_ACTION_TEXT = "Action";
+               const string BUTTON_DELETE_TEXT = "Delete";
+
+               List<int> _list;
+               public List<int> List
                {
-                       var list = new List<int>();
-                       for (var i = 0; i < 10; i++)
-                               list.Add(i);
+                       get 
+                       {
+                               if (_list == null)
+                               {
+                                       _list = new List<int>();
+                                       for (var i = 0; i < 10; i++)
+                                               _list.Add(i);
+                               }
 
+                               return _list;
+                       }
+               }
+
+               protected override void Init()
+               {
                        var stackLayout = new StackLayout
                        {
                                Orientation = StackOrientation.Vertical,
@@ -34,7 +50,7 @@ namespace Xamarin.Forms.Controls.Issues
 
                        var listView = new ListView
                        {
-                               ItemsSource = list,
+                               ItemsSource = List,
                                ItemTemplate = new DataTemplate(() =>
                                {
                                        var label = new Label();
@@ -48,11 +64,11 @@ namespace Xamarin.Forms.Controls.Issues
                                                },
                                                ContextActions = { new MenuItem
                                                {
-                                                       Text = "Action"
+                                                       Text = BUTTON_ACTION_TEXT
                                                },
                                                new MenuItem
                                                {
-                                                       Text = "Delete",
+                                                       Text = BUTTON_DELETE_TEXT,
                                                        IsDestructive = true
                                                } }
                                        };
@@ -62,5 +78,39 @@ namespace Xamarin.Forms.Controls.Issues
 
                        Content = stackLayout;
                }
+
+#if UITEST && __ANDROID__
+               [Test]
+               public void Bugzilla45027Test()
+               {
+                       var firstItemList = List.First().ToString();
+                       RunningApp.WaitForElement(q => q.Marked(firstItemList));
+
+                       RunningApp.TouchAndHold(q => q.Marked(firstItemList));
+                       RunningApp.WaitForElement(q => q.Marked(BUTTON_ACTION_TEXT));
+                       RunningApp.DoubleTap(q => q.Marked(BUTTON_ACTION_TEXT));
+
+                       RunningApp.TouchAndHold(q => q.Marked(firstItemList));
+                       RunningApp.WaitForElement(q => q.Marked(BUTTON_DELETE_TEXT));
+                       RunningApp.DoubleTap(q => q.Marked(BUTTON_DELETE_TEXT));
+               }
+#endif
+
+#if UITEST && __IOS__
+               [Test]
+               public void Bugzilla45027Test()
+               {
+                       var firstItemList = List.First().ToString();
+                       RunningApp.WaitForElement(q => q.Marked(firstItemList));
+
+                       RunningApp.SwipeRightToLeft(q => q.Marked(firstItemList));
+                       RunningApp.WaitForElement(q => q.Marked(BUTTON_ACTION_TEXT));
+                       RunningApp.DoubleTap(q => q.Marked(BUTTON_ACTION_TEXT));
+
+                       RunningApp.SwipeRightToLeft(q => q.Marked(firstItemList));
+                       RunningApp.WaitForElement(q => q.Marked(BUTTON_DELETE_TEXT));
+                       RunningApp.DoubleTap(q => q.Marked(BUTTON_DELETE_TEXT));
+               }
+#endif
        }
 }
\ No newline at end of file