on xenial help sign in
Make findChild stubborn by default
commit2123eb85a38b1fbc80a24437a9cd05e7e74bbb38 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 12 May 2016, 12:11 (10 years ago) parent844709c
2 files changed+25−5
tests/qmltests/Dash/tst_Dash.qml−1 tests/utils/modules/Unity/Test/UnityTestCase.qml+25−4
tests/qmltests/Dash/tst_Dash.qml−1
@@ -629,7 +629,6 @@ Item {
629629 touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
630630 var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
631631 tryCompare(bottomEdgeController, "progress", 1);
632− tryCompareFunction(function () { return findChild(dash, "scopesListCategoryother") !== null; }, true);
633632 var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
634633 var nonfavScopesListCategoryList = findChild(nonfavScopesListCategory, "scopesListCategoryInnerList");
635634 tryCompare(nonfavScopesListCategoryList, "currentIndex", 0);
tests/utils/modules/Unity/Test/UnityTestCase.qml+25−4
@@ -175,11 +175,11 @@ TestCase {
175175
176176
177177 // Find an object with the given name in the children tree of "obj"
178− function findChild(obj, objectName) {
178+ function findChild(obj, objectName, timeout) {
179179 if (!obj)
180180 qtest_fail("no obj given", 1);
181181
182− return findChildIn(obj, "children", objectName);
182+ return findChildInWithTimeout(obj, "children", objectName);
183183 }
184184
185185 // Find an object with the given name in the children tree of "obj"
@@ -187,11 +187,32 @@ TestCase {
187187 // Note: you should use findChild if you're not sure you need this
188188 // as this tree is much bigger and might contain stuff that goes
189189 // away randomly.
190− function findInvisibleChild(obj, objectName) {
190+ function findInvisibleChild(obj, objectName, timeout) {
191191 if (!obj)
192192 qtest_fail("no obj given", 1);
193193
194− return findChildIn(obj, "data", objectName);
194+ return findChildInWithTimeout(obj, "data", objectName, timeout);
195+ }
196+
197+ // Find a child in the named property with timeout
198+ function findChildInWithTimeout(obj, prop, objectName, timeout) {
199+ if (!obj)
200+ qtest_fail("no obj given", 1);
201+
202+ var timeSpent = 0
203+ if (timeout === undefined)
204+ timeout = 5000;
205+
206+ var child = findChildIn(obj, prop, objectName);
207+
208+ while (timeSpent < timeout && !child) {
209+ child = findChildIn(obj, prop, objectName);
210+ if (!child) {
211+ wait(50)
212+ timeSpent += 50
213+ }
214+ }
215+ return child;
195216 }
196217
197218 // Find a child in the named property