diff options
Diffstat (limited to 'src/imports/testlib/TestCase.qml')
-rw-r--r-- | src/imports/testlib/TestCase.qml | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 8d9f6822f4..700c9112eb 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -633,17 +633,45 @@ Item { \since 5.4 \qmlmethod QtObject TestCase::findChild(parent, objectName) - Returns the first child of \a parent with \a objectName, - or \c null if no such item exists. Children are searched recursively. + Returns the first child of \a parent with \a objectName, or \c null if + no such item exists. Both visual and non-visual children are searched + recursively, with visual children being searched first. \code compare(findChild(item, "childObject"), expectedChildObject); \endcode */ function findChild(parent, objectName) { + // First, search the visual item hierarchy. + var child = qtest_findVisualChild(parent, objectName); + if (child) + return child; + + // If it's not a visual child, it might be a QObject child. return qtest_results.findChild(parent, objectName); } + /*! \internal */ + function qtest_findVisualChild(parent, objectName) { + if (!parent || parent.children === undefined) + return null; + + for (var i = 0; i < parent.children.length; ++i) { + // Is this direct child of ours the child we're after? + var child = parent.children[i]; + if (child.objectName === objectName) + return child; + } + + for (i = 0; i < parent.children.length; ++i) { + // Try the direct child's children. + child = qtest_findVisualChild(parent.children[i], objectName); + if (child) + return child; + } + return null; + } + /*! \qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000, message = "") |