aboutsummaryrefslogtreecommitdiffstats
path: root/tests/system/suite_WELP/tst_WELP01/test.py
blob: 77d8c33c6d14a56950b493d15def7270d5eed8e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright (C) 2016 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

source("../../shared/qtcreator.py")

getStarted = 'Get Started'

def clickItemVerifyHelpCombo(button, expectedHelpComboRegex, testDetails):
    global getStarted
    mouseClick(button)
    helpCombo = waitForObject(":Qt Creator_HelpSelector_QComboBox")
    if not test.verify(waitFor('re.match(expectedHelpComboRegex, str(helpCombo.currentText))',
                               5000), testDetails):
        test.log("Found %s" % str(helpCombo.currentText))
    # select "Welcome" page from left toolbar again
    switchViewTo(ViewConstants.WELCOME)
    wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(getStarted)
    return test.verify(all((wsButtonFrame, wsButtonLabel)),
                       "Verifying: '%s' button is being displayed." % getStarted)
def buttonActive(button):
    # colors of the default theme for active button on Welcome page
    (activeRed, activeGreen, activeBlue) = (69, 206, 85)
    # QPalette::Window (used background color of Welcome page buttons)
    enumQPaletteWindow = 10
    color = button.palette.color(enumQPaletteWindow)
    return color.red == activeRed and color.green == activeGreen and color.blue == activeBlue

def waitForButtonsState(projectsActive, examplesActive, tutorialsActive, timeout=5000):
    projButton = getWelcomeScreenSideBarButton('Projects')[0]
    exmpButton = getWelcomeScreenSideBarButton('Examples')[0]
    tutoButton = getWelcomeScreenSideBarButton('Tutorials')[0]
    if not all((projButton, exmpButton, tutoButton)):
        return False
    return waitFor('buttonActive(projButton) == projectsActive '
                   'and buttonActive(exmpButton) == examplesActive '
                   'and buttonActive(tutoButton) == tutorialsActive', timeout)

def checkTableViewForContent(tableViewStr, expectedRegExTitle, section, atLeastOneText):
    try:
        tableView = findObject(tableViewStr) # waitForObject does not work - visible is 0?
        model = tableView.model()

        children = [ch for ch in object.children(tableView) if className(ch) == 'QModelIndex']
        for child in children:
            match = re.match(expectedRegExTitle, str(model.data(child).toString()))
            if match:
                test.passes(atLeastOneText, "Found '%s'" % match.group())
                return
        test.fail("No %s are displayed on Welcome page (%s)" % (section.lower(), section))
    except:
        test.fail("Failed to get tableview to check content of Welcome page (%s)" % section)

def main():
    global getStarted
    # open Qt Creator
    startQC()
    if not startedWithoutPluginError():
        return

    setFixedHelpViewer(HelpViewer.HELPMODE)
    addCurrentCreatorDocumentation()

    buttonsAndState = {'Projects':False, 'Examples':True, 'Tutorials':False}
    for button, state in buttonsAndState.items():
        wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(button)
        if test.verify(all((wsButtonFrame, wsButtonLabel)),
                       "Verified whether '%s' button is shown." % button):
            test.compare(buttonActive(wsButtonFrame), state,
                         "Verifying whether '%s' button is active (%s)." % (button, state))

    # select Projects and roughly check this
    switchToSubMode('Projects')
    for button in ['Create Project...', 'Open Project...']:
        wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(button)
        if test.verify(all((wsButtonFrame, wsButtonLabel)),
                       "Verified whether '%s' button is shown." % button):
            test.verify(not buttonActive(wsButtonFrame),
                        "Verifying whether '%s' button is inactive." % button)

    wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(getStarted)
    if test.verify(all((wsButtonFrame, wsButtonLabel)),
                   "Verifying: Qt Creator displays Welcome Page with '%s' button." % getStarted):
        if clickItemVerifyHelpCombo(wsButtonLabel, "Getting Started | Qt Creator Manual",
                                    "Verifying: Help with Creator Documentation is being opened."):

            textUrls = {'Online Community':'https://forum.qt.io',
                        'Blogs':'https://planet.qt.io',
                        'Qt Account':'https://account.qt.io',
                        'User Guide':'qthelp://org.qt-project.qtcreator/doc/index.html'
                        }
            for text, url in textUrls.items():
                button, label = getWelcomeScreenBottomButton(text)
                if test.verify(all((button, label)),
                               "Verifying whether link button (%s) exists." % text):
                    test.compare(str(button.toolTip), url, "Verifying URL for %s" % text)
    wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(getStarted)
    if wsButtonLabel is not None:
        mouseClick(wsButtonLabel)
        qcManualQModelIndexStr = getQModelIndexStr("text~='Qt Creator Manual [0-9.]+'",
                                                   ":Qt Creator_QHelpContentWidget")
        if str(waitForObject(":Qt Creator_HelpSelector_QComboBox").currentText) == "(Untitled)":
            mouseClick(qcManualQModelIndexStr)
            test.warning("Clicking '%s' the second time showed blank page (Untitled)" % getStarted)
    else:
        test.fatal("Something's wrong - failed to find/click '%s' the second time." % getStarted)

    # select "Welcome" page from left toolbar again
    switchViewTo(ViewConstants.WELCOME)
    wsButtonFrame, wsButtonLabel = getWelcomeScreenSideBarButton(getStarted)
    test.verify(wsButtonFrame is not None and wsButtonLabel is not None,
                "Verifying: Getting Started topic is being displayed.")
    # select Examples and roughly check them
    switchToSubMode('Examples')
    test.verify(waitForButtonsState(False, True, False), "Buttons' states have changed.")

    expect = (("QListView", "unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'",
               "examples list"),
              ("QLineEdit", "placeholderText='Search in Examples...'", "examples search line edit"),
              ("QComboBox", "currentText~='.*Qt.*'", "Qt version combo box"))
    search = "{type='%s' %s}"
    for (qType, prop, info) in expect:
        test.verify(checkIfObjectExists(search % (qType, prop)),
                    "Verifying whether %s is shown" % info)
    checkTableViewForContent(search % (expect[0][0], expect[0][1]), ".*Example", "Examples",
                             "Verifying that at least one example is displayed.")

    # select Tutorials and roughly check them
    switchToSubMode('Tutorials')
    test.verify(waitForButtonsState(False, False, True), "Buttons' states have changed.")
    expect = (("QListView", "unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'",
               "tutorials list"),
              ("QLineEdit", "placeholderText='Search in Tutorials...'",
               "tutorials search line edit"))
    for (qType, prop, info) in expect:
        test.verify(checkIfObjectExists(search % (qType, prop)),
                    "Verifying whether %s is shown" % info)
    checkTableViewForContent(search % (expect[0][0], expect[0][1]), "Help: Creating .*", "Tutorials",
                             "Verifying that at least one tutorial is displayed.")
    # exit Qt Creator
    invokeMenuItem("File", "Exit")