1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2014 Canonical Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
3
17
""" ContactListPage emulator for Addressbook App tests """
5
# Copyright 2014 Canonical
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
13
22
from autopilot.introspection.dbus import StateNotFoundError
14
from ubuntuuitoolkit import emulators as uitk
24
from address_book_app.pages import _common, _contact_view
16
27
LOGGER = logging.getLogger(__name__)
17
from time import sleep
20
class ContactListPage(uitk.UbuntuUIToolkitEmulatorBase):
30
class ContactListPage(_common.PageWithHeader, _common.PageWithBottomEdge):
21
31
""" ContactListPage emulator class """
23
33
def __init__(self, *args):
26
36
self.selected_marks = []
27
37
super(ContactListPage, self).__init__(*args)
39
def open_contact(self, index):
40
"""Open the page with the contact information.
42
:param index: The index of the contact to open.
43
:return: The page with the contact information.
46
contacts = self.get_contacts()
47
contact_delegate = contacts[index]
48
self.pointing_device.click_object(contact_delegate)
49
contact_delegate.state.wait_for('expanded')
50
details_button = contact_delegate.select_single("Icon",
51
objectName="infoIcon")
52
self.pointing_device.click_object(details_button)
53
return self.get_root_instance().select_single(
54
_contact_view.ContactView, objectName='contactViewPage')
56
def _get_list_view(self):
57
return self.wait_select_single("ContactListView",
58
objectName="contactListView")
29
60
def get_contacts(self):
31
62
Returns a list of ContactDelegate objects and populate
32
63
self.selection_marks
35
66
self.contacts = self.select_many("ContactDelegate")
36
67
self.selection_marks = []
37
68
for contact in self.contacts:
41
72
self.selection_marks.append(mark)
42
73
return self.contacts
75
def start_selection(self, idx):
76
view = self._get_list_view()
77
if not view.isInSelectionMode:
79
self.selected_marks.append(self.selection_marks[idx])
80
self.pointing_device.move_to_object(self.contacts[idx])
81
self.pointing_device.press()
83
self.pointing_device.release()
84
view.isInSelectionMode.wait_for(True)
86
self.selected_marks.append(self.selection_marks[idx])
87
self.pointing_device.click_object(self.selection_marks[idx])
44
90
def select_contacts_by_index(self, indices):
45
91
""" Select contacts corresponding to the list of index in indices
47
93
:param indices: List of integers
49
95
self.deselect_all()
97
self.start_selection(indices[0])
51
# Select matching indices
53
self.selected_marks.append(self.selection_marks[idx])
54
self.pointing_device.click_object(self.selection_marks[idx])
99
# Select matching indices
100
for idx in indices[1:]:
101
self.selected_marks.append(self.selection_marks[idx])
102
self.pointing_device.click_object(self.selection_marks[idx])
56
104
def deselect_all(self):
57
105
"""Deselect every contacts"""
63
111
objectName="selectionMark")
64
112
self.pointing_device.click_object(mark)
66
def click_button(self, objectname):
114
def click_button(self, parent, objectname):
67
115
"""Press a button that matches objectname
69
117
:param objectname: Name of the object
72
buttons = self.select_many("Button",
124
buttons = obj.select_many("Button",
73
125
objectName=objectname)
74
126
for button in buttons:
75
127
if button.visible:
84
"""Press the cancel button displayed when pick mode is enabled"""
85
self.click_button("DialogButtons.rejectButton")
88
"""Press the delete button displayed when pick mode is enabled"""
89
self.click_button("DialogButtons.acceptButton")
135
def delete(self, main_window):
136
main_window.done_selection()
137
dialog = main_window.wait_select_single("RemoveContactsDialog",
138
objectName="removeContactsDialog")
139
self.click_button(main_window, "removeContactsDialog.Yes")