From e93014efbda35218a0864588b2de03ab0d5bc4a6 Mon Sep 17 00:00:00 2001 From: Rodja Trappe Date: Wed, 3 Mar 2021 04:15:56 +0100 Subject: [PATCH] Fixing order of elements returned by "Find", so TapNth can use the correct index --- QuickTest/ElementSearch.cs | 6 +++--- Tests/ToolingTests.cs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/QuickTest/ElementSearch.cs b/QuickTest/ElementSearch.cs index e512034..9b17c51 100644 --- a/QuickTest/ElementSearch.cs +++ b/QuickTest/ElementSearch.cs @@ -17,6 +17,9 @@ public static List Find(this Element element, Predicate pr if (containerPredicate != null && !containerPredicate.Invoke(element)) return result; + if (predicate.Invoke(element)) + result.Add(ElementInfo.FromElement(element)); + result.AddRange(FindInTitle(element, predicate, containerPredicate)); result.AddRange((element as ContentPage)?.Content?.Find(predicate, containerPredicate) ?? empty); result.AddRange((element as ContentView)?.Content.Find(predicate, containerPredicate) ?? empty); @@ -25,9 +28,6 @@ public static List Find(this Element element, Predicate pr result.AddRange((element as ListView)?.Find(predicate, containerPredicate) ?? empty); result.AddRange((element as ViewCell)?.View?.Find(predicate, containerPredicate) ?? empty); - if (predicate.Invoke(element)) - result.Add(ElementInfo.FromElement(element)); - AddTapGestureRecognizers(element, result); return result; diff --git a/Tests/ToolingTests.cs b/Tests/ToolingTests.cs index f15c61e..ae06930 100644 --- a/Tests/ToolingTests.cs +++ b/Tests/ToolingTests.cs @@ -78,6 +78,23 @@ public void TestTapNth() TapNth("Label", 0); } + [Test] + public void TestTapElementWithIdenticalTitle() + { + OpenMenu("Elements"); + + // set itentical title for button and page title + (Find("Button").First() as DemoButton).Text = "Element demo"; + ShouldSee("Element demo", 2); + + var elements = Find("Element demo"); + Assert.That(elements.First(), Is.TypeOf()); + Assert.That(elements.Last(), Is.TypeOf()); + + TapNth("Element demo", 1); + Tap("Ok"); + } + [Test] public void TestFind() {