1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
""" 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
from autopilot.introspection.dbus import StateNotFoundError
14
from ubuntuuitoolkit import emulators as uitk
16
LOGGER = logging.getLogger(__name__)
17
from time import sleep
20
class ContactListPage(uitk.UbuntuUIToolkitEmulatorBase):
21
""" ContactListPage emulator class """
23
def __init__(self, *args):
25
self.selection_marks = []
26
self.selected_marks = []
27
super(ContactListPage, self).__init__(*args)
29
def get_contacts(self):
31
Returns a list of ContactDelegate objects and populate
35
self.contacts = self.select_many("ContactDelegate")
36
self.selection_marks = []
37
for contact in self.contacts:
39
mark = contact.select_single("QQuickRectangle",
40
objectName="selectionMark")
41
self.selection_marks.append(mark)
44
def select_contacts_by_index(self, indices):
45
""" Select contacts corresponding to the list of index in indices
47
:param indices: List of integers
51
# Select matching indices
53
self.selected_marks.append(self.selection_marks[idx])
54
self.pointing_device.click_object(self.selection_marks[idx])
56
def deselect_all(self):
57
"""Deselect every contacts"""
58
contacts = self.select_many("ContactDelegate")
59
self.selected_marks = []
60
for contact in contacts:
62
mark = contact.select_single("QQuickRectangle",
63
objectName="selectionMark")
64
self.pointing_device.click_object(mark)
66
def click_button(self, objectname):
67
"""Press a button that matches objectname
69
:param objectname: Name of the object
72
buttons = self.select_many("Button",
73
objectName=objectname)
74
for button in buttons:
76
self.pointing_device.click_object(button)
77
except StateNotFoundError:
79
'Button with objectName "{0}" not found.'.format(objectname)
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")