test.py 7.68 KB
Newer Older
1
2
#############################################################################
##
3
## Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
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
## Contact: http://www.qt-project.org/legal
##
## 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 Digia.  For licensing terms and
## conditions see http://qt.digia.com/licensing.  For further information
## use the contact form at http://qt.digia.com/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file.  Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Digia gives you certain additional
## rights.  These rights are described in the Digia Qt LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
#############################################################################

30
31
32
33
34
35
source("../../shared/qtcreator.py")
import re

# test search in help mode and advanced search
searchKeywordDictionary={ "deployment":True, "deplmint":False, "build":True, "bld":False }

Christian Stenger's avatar
Christian Stenger committed
36

37
def __getSelectedText__():
Christian Stenger's avatar
Christian Stenger committed
38
    hv = findObject(":Qt Creator_Help::Internal::HelpViewer")
39
    try:
Christian Stenger's avatar
Christian Stenger committed
40
        selText = hv.selectedText
41
42
43
44
45
46
47
48
49
50
51
        if className(selText) != 'instancemethod':
            return str(selText)
    except:
        pass
    try:
        selText = getHighlightsInHtml(str(hv.toHtml()))
    except:
        test.warning("Could not get highlighted text.")
        selText = ''
    return str(selText)

Christian Stenger's avatar
Christian Stenger committed
52
53
54
55
56
57
58
59
60
61
62
63
def __getUrl__():
    helpViewer = findObject(":Qt Creator_Help::Internal::HelpViewer")
    try:
        url = helpViewer.url
    except:
        try:
            url = helpViewer.source
        except:
            return ""
    if isQt4Build:
        return str(url.toString())
    return str(url.scheme) + "://" + str(url.host) + str(url.path)
64
65
66
67
68
69
70
71
72
73
74

def getHighlightsInHtml(htmlCode):
    pattern = re.compile('color:#ff0000;">(.*?)</span>')
    res = ""
    for curr in pattern.finditer(htmlCode):
        if curr.group(1) in res:
            continue
        res += "%s " % curr.group(1)
    return res

def main():
Christian Stenger's avatar
Christian Stenger committed
75
    global sdkPath
76
77
    noMatch = "Your search did not match any documents."
    startApplication("qtcreator" + SettingsPath)
78
79
    if not startedWithoutPluginError():
        return
Christian Stenger's avatar
Christian Stenger committed
80
    addHelpDocumentation([os.path.join(sdkPath, "Documentation", "qt.qch")])
81
82
83
    # switch to help mode
    switchViewTo(ViewConstants.HELP)
    # verify that search widget is accessible
84
85
86
    mouseClick(waitForObjectItem(":Qt Creator_Core::Internal::CommandComboBox", "Search"))
    test.verify(checkIfObjectExists("{type='QHelpSearchQueryWidget' unnamed='1' visible='1' "
                                    "window=':Qt Creator_Core::Internal::MainWindow'}"),
87
88
                "Verifying search widget visibility.")
    # try to search empty string
89
90
    clickButton(waitForObject("{text='Search' type='QPushButton' unnamed='1' visible='1' "
                              "window=':Qt Creator_Core::Internal::MainWindow'}"))
91
92
93
94
95
    progressBarWait()
    test.verify(waitFor("noMatch in "
                        "str(waitForObject(':Hits_QCLuceneResultWidget').plainText)", 2000),
                        "Verifying if search did not match anything.")
    # workaround for "endless waiting cursor"
96
97
    mouseClick(waitForObject("{column='0' container=':Qt Creator_QHelpContentWidget' "
                             "text='Qt Reference Documentation' type='QModelIndex'}"))
98
99
    # try to search keyword from list
    for searchKeyword,shouldFind in searchKeywordDictionary.items():
100
101
102
        mouseClick(waitForObject(":Qt Creator.Help_Search for:_QLineEdit"))
        replaceEditorContent(":Qt Creator.Help_Search for:_QLineEdit", searchKeyword)
        type(waitForObject(":Qt Creator.Help_Search for:_QLineEdit"), "<Return>")
103
        progressBarWait(warn=False)
104
105
106
107
108
        if shouldFind:
            test.verify(waitFor("re.match('[1-9]\d* - [1-9]\d* of [1-9]\d* Hits',"
                                "str(findObject(':Hits_QLabel').text))", 2000),
                                "Verifying if search results found with 1+ hits for: " + searchKeyword)
            selText = __getSelectedText__()
Christian Stenger's avatar
Christian Stenger committed
109
            url = __getUrl__()
110
111
112
113
            # click in the widget, tab to first item and press enter
            mouseClick(waitForObject(":Hits_QCLuceneResultWidget"), 1, 1, 0, Qt.LeftButton)
            type(waitForObject(":Hits_QCLuceneResultWidget"), "<Tab>")
            type(waitForObject(":Hits_QCLuceneResultWidget"), "<Return>")
114
            waitFor("__getUrl__() != url or selText != __getSelectedText__()", 20000)
115
116
117
118
119
120
121
122
            # verify if search keyword is found in results
            test.verify(searchKeyword.lower() in __getSelectedText__().lower(),
                        searchKeyword + " search result can be found")
        else:
            test.verify(waitFor("noMatch in "
                                "str(waitForObject(':Hits_QCLuceneResultWidget').plainText)", 1000),
                                "Verifying if search did not match anything for: " + searchKeyword)
    # advanced search - setup
123
124
125
126
127
128
129
130
131
132
133
134
135
    clickButton(waitForObject("{text='+' type='QToolButton' unnamed='1' visible='1' "
                              "window=':Qt Creator_Core::Internal::MainWindow'}"))
    label = ("{text='%s' type='QLabel' unnamed='1' visible='1' "
             "window=':Qt Creator_Core::Internal::MainWindow'}")
    lineEdit = ("{leftWidget=%s type='QLineEdit' unnamed='1' visible='1' "
                "window=':Qt Creator_Core::Internal::MainWindow'}")
    labelTextsToSearchStr = {"words <B>similar</B> to:":"deploy",
                             "<B>without</B> the words:":"bookmark",
                             "with <B>exact phrase</B>:":"sql in qt",
                             "with <B>all</B> of the words:":"designer sql",
                             "with <B>at least one</B> of the words:":"printing"}
    for labelText,searchStr in labelTextsToSearchStr.items():
        type(waitForObject(lineEdit % (label % labelText)), searchStr)
136
    # advanced search - do search
137
138
    clickButton(waitForObject("{text='Search' type='QPushButton' unnamed='1' visible='1' "
                              "window=':Qt Creator_Core::Internal::MainWindow'}"))
139
    progressBarWait(warn=False)
140
141
142
143
144
145
146
147
    # verify that advanced search results found
    test.verify(waitFor("re.search('1 - 2 of 2 Hits',"
                        "str(findObject(':Hits_QLabel').text))", 3000),
                        "Verifying if 2 search results found")
    resultsView = waitForObject(":Hits_QCLuceneResultWidget")
    mouseClick(resultsView, 1, 1, 0, Qt.LeftButton)
    type(resultsView, "<Tab>")
    type(resultsView, "<Return>")
Christian Stenger's avatar
Christian Stenger committed
148
    test.verify("printing" in str(__getSelectedText__()).lower(),
149
150
151
152
                "printing advanced search result can be found")
    for i in range(2):
        type(resultsView, "<Tab>")
    type(resultsView, "<Return>")
Christian Stenger's avatar
Christian Stenger committed
153
    test.verify("sql" in str(__getSelectedText__()).lower(),
154
155
                "sql advanced search result can be found")
    # verify if simple search is properly disabled
156
    test.verify(findObject(":Qt Creator.Help_Search for:_QLineEdit").enabled == False,
157
158
159
                "Verifying if simple search is not active in advanced mode.")
    # exit
    invokeMenuItem("File", "Exit")