aboutsummaryrefslogtreecommitdiffstats
path: root/squishtests/suite_neptune3/tst_app_phone/steps/app_phone.py
blob: baae11dff982e09855ce9a0040937bd7ca49925f (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# -*- coding: utf-8 -*-

############################################################################
##
## Copyright (C) 2019 Luxoft Sweden AB
## Contact: https://www.qt.io/licensing/
##
## This file is part of the Neptune 3 IVI UI.
##
## $QT_BEGIN_LICENSE:GPL-QTAS$
## Commercial License Usage
## Licensees holding valid commercial Qt Automotive Suite 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 or (at your option) any later version
## approved by the KDE Free Qt Foundation. The licenses are as published by
## the Free Software Foundation and appearing in the file LICENSE.GPL3
## 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.
##
## $QT_END_LICENSE$
##
## SPDX-License-Identifier: GPL-3.0
##
############################################################################

# squish dependent
import names
import common.qml_names as qml
import common.app as app


@OnFeatureStart
def hook(context):
    start_neptune_ui_app_w_focus("console")


@Then("tap phone '|word|' button")
def step(context, button_name):
    if button_name not in qml.viewPhoneButtons:
        test.fail("in phone the button '" + button_name
                 + "' is not known!!")
        return
    app.switch_to_app('phone')
    start_search = waitForObject(names.phoneViewChangeButtons_ToolsColumn)

    object_name = qml.viewPhoneButton_prefix + button_name
    object_pointer = find_object_name_recursively(start_search, object_name, 4)
    if object_pointer is not None:
        if object_pointer.visible:
            squish.tapObject(object_pointer)
        else:
            app.fail("phone button '" + button_name
                     + "' was found but is not visible!")


@Then("phone view '|word|' should be displayed")
def step(context, view_name):
    if view_name not in qml.viewPhoneButtons:
        app.fail("in phone the view '" + view_name
                 + "' is not known!!")
    # recents and favorites so far not
    has_2_views = [qml.viewPhoneButtons[2:]]

    view_obj_name = None
    if view_name == 'contacts':
        view_obj_name = names.contacts_phoneView_ContactsView
    elif view_name == 'recents':
        view_obj_name = names.recents_phoneView_RecentCallsView
    elif view_name == 'favorites':
        view_obj_name = names.favorites_phoneView_ContactsView
    elif view_name == 'keypad':
        view_obj_name = names.keypad_phoneView_KeypadViewPanel
    else:
        app.fail("this should not happen, this view '"
                 + view_name + "'" is not known)

    view_found = squish.waitForObject(view_obj_name)
    # first test (since it is not the last no "app.compare()"
    test.compare(view_found is not None, True, "view '"
                + view_name + "' found!!")

    if view_name in has_2_views:
        if view_name == 'favorites':
            second_ui_item = names.phonefavoritesView_FavoritesWidgetView
        elif view_name == 'keypad':
            second_ui_item = names.phoneCallView_CallWidgetView
        else:
            app.fail("this should not happen here with '"
                     + view_name + "'!!")
        test_ui = squish.waitForObject(second_ui_item)
        app.compare(test_ui.visible, True, "2nd view item should be visible")

    # switch to main before new command
    app.switch_to_main_app()
    squish.snooze(0.2)


@When("tapping call icon of '|word|' entry '|integer|'")
def step(context, view_name, entry_number):
    if not context.userData:
        context.userData = {}

    natural_number = entry_number - 1
    ui_item = None
    caller_prefix = qml.phone_contactView_prefix
    button_prefix = qml.phone_contactView_button_prefix
    name_prefix = qml.phone_contactView_caller_prefix
    if view_name == 'favorites':
        ui_item = names.favorites_phoneView_ContactsView
    elif view_name == 'contacts':
        ui_item = names.contacts_phoneView_ContactsView
    else:
        app.fail("from this view you cannot call directly: '"
                 + view_name + "'!!")
    # switch to app
    app.switch_to_app('phone')
    caller_view = squish.waitForObject(ui_item)

    if caller_view is not None:
        search_contact_name = caller_prefix + str(natural_number)
        caller_pointer = find_object_name_recursively(caller_view,
                                                      search_contact_name, 4)
        if caller_pointer is not None:
            search_contact_button_name = button_prefix + str(natural_number)
            button_pointer = find_object_name_recursively(caller_pointer,
                                                    search_contact_button_name,
                                                    4)
            if button_pointer is not None:
                # now store the name for comparison
                store_name = name_prefix + str(natural_number)
                name_obj = find_object_name_recursively(caller_pointer,
                                                        store_name,
                                                        4)
                if name_obj is not None:
                    full_name = str(name_obj.text)
                    context.userData['calling'] = full_name
                    # and finally hit 'call'
                    squish.tapObject(button_pointer)
                else:
                    app.fail("name for contact '"
                             + button_prefix
                             + str(natural_number)
                             + "' could not be found")
            else:
                app.fail("button for contact '"
                         + button_prefix
                         + str(natural_number)
                         + "' could not be found")
        else:
            app.fail("stackview item for '"
                     + view_name + str(natural_number)
                     + "' could not be found")
    else:
        app.fail("should not happen here!!!")

    # switch to main before new command
    app.switch_to_main_app()
    squish.snooze(0.2)


@When("tapping the buttons in order '|word|'")
def step(context, number_sequence):
    button_sequence = []

    for i in range(len(number_sequence)):
        my_char = number_sequence[i]
        resolved_name = my_char if my_char >= '0' and my_char <= '9' else(
                    "asterisk" if my_char == "*" else (
                    "hash" if my_char == "#" else "error"))
        if resolved_name != "error":
            keypad_name = qml.phone_numpad_prefix + resolved_name
            button_sequence.append(keypad_name)
        else:
            app.fail("The character '" + my_char + "' cannot be dialed")
            return

    # switch to app
    app.switch_to_app('phone')
    squish.snooze(0.25)

    for elem in button_sequence:
        button_obj = {"container": names.container_phone, "objectName": elem,
                      "type": "KeypadButton", "visible": True}
        squish.waitForObject(button_obj)
        squish.snooze(0.1)
        squish.tapObject(button_obj)

    app.switch_to_main_app()


@Then("number '|word|' should be displayed")
def step(context, number_sequence):
    # switch to app
    app.switch_to_app('phone')
    squish.snooze(0.25)

    number_textobj = squish.waitForObject(names.callNumber_TextEdit)
    found_number = str(number_textobj.text)
    app.compare(number_sequence, found_number, "numbers should be equal")


@Then("clear number display")
def step(context):
    # switch to app
    app.switch_to_app('phone')
    squish.snooze(0.25)

    number_textobj = squish.waitForObject(names.callNumber_TextEdit)
    found_number = str(number_textobj.text)

    # clear field by tapping del length(text) times
    for _i in range(len(found_number)):
        del_button = squish.waitForObject(names.delLastCallDigitButton)
        squish.snooze(0.05)
        squish.tapObject(del_button)
    app.switch_to_main_app()