From 8d383746caab00dd3ee0b62dc992a2a99c7a6d06 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Wed, 4 May 2016 08:16:42 -0600 Subject: Remove empty UI tests (#160) * Use WaitForElement instead of Thread.Sleep to cut down on idle time * Remove empty UI tests --- .../Utilities/AppExtensions.cs | 84 ++-------------------- 1 file changed, 6 insertions(+), 78 deletions(-) (limited to 'Xamarin.Forms.Core.iOS.UITests/Utilities') diff --git a/Xamarin.Forms.Core.iOS.UITests/Utilities/AppExtensions.cs b/Xamarin.Forms.Core.iOS.UITests/Utilities/AppExtensions.cs index c6f2508c..481c3a5e 100644 --- a/Xamarin.Forms.Core.iOS.UITests/Utilities/AppExtensions.cs +++ b/Xamarin.Forms.Core.iOS.UITests/Utilities/AppExtensions.cs @@ -30,87 +30,15 @@ namespace Xamarin.Forms.Core.UITests public static void NavigateToGallery (this IApp app, string page) { + const string goToTestButtonQuery = "* marked:'GoToTestButton'"; + var text = Regex.Match (page, "'(?[^']*)'").Groups["text"].Value; app.EnterText (q => q.Raw ("* marked:'SearchBar'"), text); - //var searchBar = app.Query (q => q.Raw ("* marked:'SearchBar'")).Single (); - Thread.Sleep(10000); - - app.Tap (q => q.Raw ("* marked:'GoToTestButton'")); - app.WaitForNoElement (o => o.Raw ("* marked:'GoToTestButton'"), "Timed out", TimeSpan.FromMinutes(2)); - - //app.Screenshot ("Navigating to gallery ..."); - //var galleryListViewBounds = app.Query (Queries.GalleryListView)[0].Rect; - //app.ScrollForElement (page, new Drag (galleryListViewBounds, Drag.Direction.BottomToTop, Drag.DragLength.Long)); - //app.Tap (q => q.Raw (page)); - //app.Screenshot ("At gallery!"); - } - - public static void NavigateToTestCases (this IApp app, string testCase) - { - app.Tap (q => q.Button ("Go to Test Cases")); - app.WaitForElement (q => q.Raw ("* marked:'TestCasesIssueList'")); - - app.EnterText (q => q.Raw ("* marked:'SearchBarGo'"), testCase); - - app.WaitForElement (q => q.Raw ("* marked:'SearchButton'")); - app.Tap (q => q.Raw ("* marked:'SearchButton'")); - - //app.NavigateToTestCase(testCase); - } - - public static void NavigateToTestCase (this IApp app, string testCase) - { - string testCasesQuery = "* marked:'" + testCase + "'"; - var testCaseIssue = app.Query (q => q.Raw ("* marked:'TestCasesIssueList'")).FirstOrDefault (); - if (testCaseIssue != null) { - AppRect scrollRect = testCaseIssue.Rect; - app.ScrollForElement (testCasesQuery, new Drag (scrollRect, Drag.Direction.BottomToTop, Drag.DragLength.Long)); - app.Tap (q => q.Raw (testCasesQuery)); - } else { - Debug.WriteLine (string.Format ("Failed to find test case {0}", testCase)); - } - } - - public static bool RectsEqual (AppRect rectOne, AppRect rectTwo) - { - const float equalsTolerance = 0.1f; - - bool areEqual = - (Math.Abs (rectOne.X - rectTwo.X) < equalsTolerance) && - (Math.Abs (rectOne.Y - rectTwo.Y) < equalsTolerance) && - (Math.Abs (rectOne.Width - rectTwo.Width) < equalsTolerance) && - (Math.Abs (rectOne.Height - rectTwo.Height) < equalsTolerance) && - (Math.Abs (rectOne.CenterX - rectTwo.CenterX) < equalsTolerance) && - (Math.Abs (rectOne.CenterY - rectTwo.CenterY) < equalsTolerance); - - return areEqual; - } - - public static void WaitForAnimating (this IApp app, Func query) - { - // Right now only checks if bounds are moving - const int pollingRate = 200; - const int timeout = 5000; - var sw = new Stopwatch (); - - var previousState = app.Query (query).First ().Rect; - - sw.Start (); - while (true) { - - var newState = app.Query (query).First ().Rect; - - if (RectsEqual (previousState, newState)) - break; - - previousState = newState; - - if (sw.ElapsedMilliseconds >= timeout) - throw new Exception("Timed out"); + + app.WaitForElement(q => q.Raw(goToTestButtonQuery), "Timed out waiting for Go To Test button to disappear", TimeSpan.FromSeconds(10)); - Thread.Sleep (pollingRate); - } - sw.Stop (); + app.Tap (q => q.Raw (goToTestButtonQuery)); + app.WaitForNoElement (o => o.Raw (goToTestButtonQuery), "Timed out waiting for Go To Test button to disappear", TimeSpan.FromMinutes(2)); } } } -- cgit v1.2.3