From 892ccd2097ece7e8f77ab278dc83d83f6cc0ce7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20L=C3=B6hning?= Date: Mon, 3 Apr 2023 16:15:25 +0200 Subject: [PATCH] SquishTests: Add function for finding elements of project tree Change-Id: I08c3c22a404d2b58bdb1205f22e5cf937c6027b0 Reviewed-by: Reviewed-by: Christian Stenger --- tests/system/shared/project_explorer.py | 31 +++++++++++++++++----- tests/system/suite_QMLS/tst_QMLS04/test.py | 5 ++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/system/shared/project_explorer.py b/tests/system/shared/project_explorer.py index 8f50fae7e62..ca7952022ee 100644 --- a/tests/system/shared/project_explorer.py +++ b/tests/system/shared/project_explorer.py @@ -96,16 +96,33 @@ def getExecutableAndTargetFromToolTip(toolTip): return None, target return exe.group(1).strip(), target + +# treeElement is the dot-separated tree to the wanted element, e.g. +# root.first.second.leaf +def waitForProjectTreeItem(treeElement, timeoutMSec): + projectTV = ":Qt Creator_Utils::NavigationTreeView" + projItem = None + treeElementWithBranch = addBranchWildcardToRoot(treeElement) + for _ in range(timeoutMSec / 200): + try: + projItem = waitForObjectItem(projectTV, treeElement, 100) + except: + try: + projItem = waitForObjectItem(projectTV, treeElementWithBranch, 100) + except: + pass + if projItem: + return projItem + raise LookupError("Could not find project tree element: %s or %s" + % (treeElement, treeElementWithBranch)) + + def invokeContextMenuOnProject(projectName, menuItem): try: - projItem = waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", projectName, 3000) + projItem = waitForProjectTreeItem(projectName, 4000) except: - try: - projItem = waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", - addBranchWildcardToRoot(projectName), 1000) - except: - test.fatal("Failed to find root node of the project '%s'." % projectName) - return + test.fatal("Failed to find root node of the project '%s'." % projectName) + return openItemContextMenu(waitForObject(":Qt Creator_Utils::NavigationTreeView"), str(projItem.text).replace("_", "\\_").replace(".", "\\."), 5, 5, 0) activateItem(waitForObjectItem("{name='Project.Menu.Project' type='QMenu' visible='1'}", menuItem)) diff --git a/tests/system/suite_QMLS/tst_QMLS04/test.py b/tests/system/suite_QMLS/tst_QMLS04/test.py index bcb282560b9..351b59ac638 100644 --- a/tests/system/suite_QMLS/tst_QMLS04/test.py +++ b/tests/system/suite_QMLS/tst_QMLS04/test.py @@ -41,10 +41,9 @@ def main(): # there should be new QML file generated with name "MyComponent.qml" try: # openDocument() doesn't wait for expected elements, so it might be faster than the updates - # to the tree. Explicitly wait here to avoid timing issues. Using wFOI() instead of + # to the tree. Explicitly wait here to avoid timing issues. Using wFPTI() instead of # snooze() allows to proceed earlier, just in case it can find the item. - waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", - addBranchWildcardToRoot(myCompTE), 2000) + waitForProjectTreeItem(myCompTE, 2000) except: pass # open MyComponent.qml file for verification