From 9f6f5bfee2ec0476454540c440b9687d14ea7c3f Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 7 Feb 2017 09:08:11 +0100 Subject: [PATCH] Squish: Adapt tst_WELP02 to latest Welcome page changes Additionally move common used code for interacting with the Welcome page into separate file. Change-Id: If863ae529c7c81d095f310f0a34926b324c77fa8 Reviewed-by: Robert Loehning --- tests/system/shared/project.py | 18 +++--- tests/system/shared/qtcreator.py | 1 + tests/system/shared/welcome.py | 53 ++++++++++++++++ tests/system/suite_WELP/tst_WELP01/test.py | 21 ------- tests/system/suite_WELP/tst_WELP02/test.py | 72 +++++++++++++++------- 5 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 tests/system/shared/welcome.py diff --git a/tests/system/shared/project.py b/tests/system/shared/project.py index e8e7a90330e..d3b80676d3a 100644 --- a/tests/system/shared/project.py +++ b/tests/system/shared/project.py @@ -34,10 +34,11 @@ def openQbsProject(projectPath): def openQmakeProject(projectPath, targets=Targets.desktopTargetClasses(), fromWelcome=False): cleanUpUserFiles(projectPath) if fromWelcome: - welcomePage = ":Qt Creator.WelcomePage_QQuickWidget" - mouseClick(waitForObject("{clip='false' container='%s' enabled='true' text='Open Project' " - "type='Button' unnamed='1' visible='true'}" % welcomePage), - 5, 5, 0, Qt.LeftButton) + wsButtonFrame, wsButtonLabel = getWelcomeScreenMainButton('Open Project') + if not all((wsButtonFrame, wsButtonLabel)): + test.fatal("Could not find 'Open Project' button on Welcome Page.") + return [] + mouseClick(wsButtonLabel) else: invokeMenuItem("File", "Open File or Project...") selectFromFileDialog(projectPath) @@ -82,10 +83,11 @@ def openCmakeProject(projectPath, buildDir): # this list can be used in __chooseTargets__() def __createProjectOrFileSelectType__(category, template, fromWelcome = False, isProject=True): if fromWelcome: - welcomePage = ":Qt Creator.WelcomePage_QQuickWidget" - mouseClick(waitForObject("{clip='false' container='%s' enabled='true' text='New Project' " - "type='Button' unnamed='1' visible='true'}" % welcomePage), - 5, 5, 0, Qt.LeftButton) + wsButtonFrame, wsButtonLabel = getWelcomeScreenMainButton("New Project") + if not all((wsButtonFrame, wsButtonLabel)): + test.fatal("Could not find 'New Project' button on Welcome Page") + return [] + mouseClick(wsButtonLabel) else: invokeMenuItem("File", "New File or Project...") categoriesView = waitForObject(":New.templateCategoryView_QTreeView") diff --git a/tests/system/shared/qtcreator.py b/tests/system/shared/qtcreator.py index 5e2ebeae640..afed6c118d4 100644 --- a/tests/system/shared/qtcreator.py +++ b/tests/system/shared/qtcreator.py @@ -52,6 +52,7 @@ source("../../shared/project_explorer.py") source("../../shared/hook_utils.py") source("../../shared/debugger.py") source("../../shared/clang.py") +source("../../shared/welcome.py") source("../../shared/workarounds.py") # include this at last # ATTENTION: if a test case calls startApplication("qtcreator...") for several times this diff --git a/tests/system/shared/welcome.py b/tests/system/shared/welcome.py new file mode 100644 index 00000000000..1884c50c581 --- /dev/null +++ b/tests/system/shared/welcome.py @@ -0,0 +1,53 @@ +############################################################################ +# +# Copyright (C) 2017 The Qt Company Ltd. +# Contact: https://www.qt.io/licensing/ +# +# This file is part of Qt Creator. +# +# Commercial License Usage +# Licensees holding valid commercial Qt licenses may use this file in +# accordance with the commercial license agreement provided with the +# Software or, alternatively, in accordance with the terms contained in +# a written agreement between you and The Qt Company. For licensing terms +# and conditions see https://www.qt.io/terms-conditions. For further +# information use the contact form at https://www.qt.io/contact-us. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 3 as published by the Free Software +# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +# included in the packaging of this file. Please review the following +# information to ensure the GNU General Public License requirements will +# be met: https://www.gnu.org/licenses/gpl-3.0.html. +# +############################################################################ + +def __getWelcomeScreenButtonHelper__(buttonLabel, widgetWithQFrames): + frames = [child for child in object.children(widgetWithQFrames) if className(child) == 'QFrame'] + for frame in frames: + label = getChildByClass(frame, 'QLabel') + if str(label.text) == buttonLabel: + return frame, label + return None, None + +def getWelcomeScreenSideBarButton(buttonLabel): + sideBar = waitForObject("{type='Welcome::Internal::SideBar' unnamed='1' " + "window=':Qt Creator_Core::Internal::MainWindow'}") + return __getWelcomeScreenButtonHelper__(buttonLabel, sideBar) + +def getWelcomeScreenMainButton(buttonLabel): + stackedWidget = waitForObject("{type='QWidget' unnamed='1' visible='1' " + "leftWidget={type='QWidget' unnamed='1' visible='1' " + "leftWidget={type='Welcome::Internal::SideBar' unnamed='1' " + "window=':Qt Creator_Core::Internal::MainWindow'}}}") + currentStackWidget = stackedWidget.currentWidget() + return __getWelcomeScreenButtonHelper__(buttonLabel, currentStackWidget) + +def getWelcomeTreeView(treeViewLabel): + try: + return waitForObject("{aboveWidget={text='%s' type='QLabel' unnamed='1' visible='1' " + "window=':Qt Creator_Core::Internal::MainWindow'} " + "type='QTreeView' unnamed='1' visible='1'}" % treeViewLabel) + except: + return None diff --git a/tests/system/suite_WELP/tst_WELP01/test.py b/tests/system/suite_WELP/tst_WELP01/test.py index 3165aa0c8fe..ffc16e087d4 100755 --- a/tests/system/suite_WELP/tst_WELP01/test.py +++ b/tests/system/suite_WELP/tst_WELP01/test.py @@ -57,27 +57,6 @@ def waitForButtonsState(projectsActive, examplesActive, tutorialsActive, timeout 'and buttonActive(exmpButton) == examplesActive ' 'and buttonActive(tutoButton) == tutorialsActive', timeout) -def __getWelcomeScreenButtonHelper__(buttonLabel, widgetWithQFrames): - frames = [child for child in object.children(widgetWithQFrames) if className(child) == 'QFrame'] - for frame in frames: - label = getChildByClass(frame, 'QLabel') - if str(label.text) == buttonLabel: - return frame, label - return None, None - -def getWelcomeScreenSideBarButton(buttonLabel): - sideBar = waitForObject("{type='Welcome::Internal::SideBar' unnamed='1' " - "window=':Qt Creator_Core::Internal::MainWindow'}") - return __getWelcomeScreenButtonHelper__(buttonLabel, sideBar) - -def getWelcomeScreenMainButton(buttonLabel): - stackedWidget = waitForObject("{type='QWidget' unnamed='1' visible='1' " - "leftWidget={type='QWidget' unnamed='1' visible='1' " - "leftWidget={type='Welcome::Internal::SideBar' unnamed='1' " - "window=':Qt Creator_Core::Internal::MainWindow'}}}") - currentStackWidget = stackedWidget.currentWidget() - return __getWelcomeScreenButtonHelper__(buttonLabel, currentStackWidget) - def checkTableViewForContent(tableViewStr, expectedRegExTitle, section, atLeastOneText): try: tableView = findObject(tableViewStr) # waitForObject does not work - visible is 0? diff --git a/tests/system/suite_WELP/tst_WELP02/test.py b/tests/system/suite_WELP/tst_WELP02/test.py index 47baca16391..ae7b22e9345 100644 --- a/tests/system/suite_WELP/tst_WELP02/test.py +++ b/tests/system/suite_WELP/tst_WELP02/test.py @@ -24,14 +24,44 @@ ############################################################################ source("../../shared/qtcreator.py") -source("../../shared/suites_qtta.py") - -welcomePage = ":Qt Creator.WelcomePage_QQuickWidget" def checkTypeAndProperties(typePropertiesDetails): for (qType, props, detail) in typePropertiesDetails: - test.verify(checkIfObjectExists(getQmlItem(qType, welcomePage, False, props)), - "Verifying: Qt Creator displays %s." % detail) + if qType == "QPushButton": + wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(props) + test.verify(all((wsButtonFrame, wsButtonLabel)), + "Verifying: Qt Creator displays Welcome Page with %s." % detail) + elif qType == 'QTreeView': + treeView = getWelcomeTreeView(props) + test.verify(treeView is not None, + "Verifying: Qt Creator displays Welcome Page with %s." % detail) + elif qType == 'SessionModelIndex': + # for SessionModelIndex props must be a tuple with 2 elements, the first is just + # as for others (additional properties) while the second is either True or False and + # indicating whether to check the found index for being the default and current session + treeView = getWelcomeTreeView("Sessions") + if not treeView: + test.fatal("Failed to find Sessions tree view, cannot check for %s." % detail) + continue + indices = dumpIndices(treeView.model()) + found = False + for index in indices: + if props[0] == str(index.data()): + # 257 -> DefaultSessionRole, 259 -> ActiveSessionRole [sessionmodel.h] + isDefaultAndCurrent = index.data(257).toBool() and index.data(259).toBool() + if not props[1] or isDefaultAndCurrent: + found = True + break + test.verify(found, "Verifying: Qt Creator displays Welcome Page with %s." % detail) + elif qType == 'ProjectModelIndex': + treeView = getWelcomeTreeView("Recent Projects") + if not treeView: + test.fatal("Failed to find Projects tree view, cannot check for %s." % detail) + continue + test.verify(props in dumpItems(treeView.model()), + "Verifying: Qt Creator displays Welcome Page with %s." % detail) + else: + test.fatal("Unhandled qType '%s' found..." % qType) def main(): # prepare example project @@ -44,11 +74,10 @@ def main(): if not startedWithoutPluginError(): return - typePropDet = (("Button", "text='Get Started Now' id='gettingStartedButton'", - "Get Started Now button"), - ("Text", "text='Sessions' id='sessionsTitle'", "Sessions section"), - ("Text", "text='default'", "default session listed"), - ("Text", "text='Recent Projects' id='recentProjectsTitle'", "Projects section"), + typePropDet = (("QPushButton", "Get Started Now", "Get Started Now button"), + ("QTreeView", "Sessions", "Sessions section"), + ("SessionModelIndex", ("default", False), "default session listed"), + ("QTreeView", "Recent Projects", "Projects section") ) checkTypeAndProperties(typePropDet) @@ -59,12 +88,10 @@ def main(): "Verifying: The project is opened in 'Edit' mode after configuring.") # go to "Welcome page" again and verify updated information switchViewTo(ViewConstants.WELCOME) - typePropDet = (("Text", "text='Sessions' id='sessionsTitle'", "Sessions section"), - ("Text", "text='default (current session)'", - "default session as current listed"), - ("Text", "text='Recent Projects' id='recentProjectsTitle'", "Projects section"), - ("Text", "text='SampleApp'", - "current project listed in projects section") + typePropDet = (("QTreeView", "Sessions", "Sessions section"), + ("SessionModelIndex", ("default", True), "default session as current listed"), + ("QTreeView", "Recent Projects", "Projects section"), + ("ProjectModelIndex", "SampleApp", "current project listed in projects section") ) checkTypeAndProperties(typePropDet) @@ -77,11 +104,12 @@ def main(): "Verifying: The project is opened in 'Edit' mode after configuring.") # go to "Welcome page" again and check if there is an information about recent projects switchViewTo(ViewConstants.WELCOME) - test.verify(checkIfObjectExists(getQmlItem("Text", welcomePage, False, - "text='animation'")) and - checkIfObjectExists(getQmlItem("Text", welcomePage, False, - "text='SampleApp'")), - "Verifying: 'Welcome page' displays information about recently created and " - "opened projects.") + treeView = getWelcomeTreeView('Recent Projects') + if treeView is None: + test.fatal("Cannot verify Recent Projects on Welcome Page - failed to find tree view.") + else: + typePropDet = (("ProjectModelIndex", "animation", "one project"), + ("ProjectModelIndex", "SampleApp", "other project")) + checkTypeAndProperties(typePropDet) # exit Qt Creator invokeMenuItem("File", "Exit")