From 97cd2af9ac4c9b516ddf7ed19041041444b5f5e0 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 2 Jul 2014 09:53:00 +0200 Subject: Add findChild to TestCase. This is useful for auto tests where it's necessary to have access to dynamically created child items. For example: property Component threeItemDelegate: Text { objectName: "delegate" + styleData.index text: styleData.value } ... function test_stuff() { ... var delegate0 = findChild(item, "delegate0"); // check delegate0 for some condition... } [ChangeLog][QtTest][TestCase] Added findChild function to TestCase. Change-Id: I04a8b07c9904768c07ec12f4b03f1afb1989e054 Reviewed-by: Liang Qi Reviewed-by: J-P Nurmi --- src/imports/testlib/TestCase.qml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/imports/testlib/TestCase.qml') diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 37addd1d7d..f946a4eef3 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -637,6 +637,21 @@ Item { return qtest_results.grabImage(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. + + \code + compare(findChild(item, "childObject"), expectedChildObject); + \endcode + */ + function findChild(parent, objectName) { + return qtest_results.findChild(parent, objectName); + } + /*! \qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000, message = "") -- cgit v1.2.3