~ken-vandine/address-book-app/add_profile

« back to all changes in this revision

Viewing changes to tests/autopilot/address_book_app/pages/_contact_list_page.py

  • Committer: CI bot
  • Author(s): Tarmac, Renato Araujo Oliveira Filho
  • Date: 2014-06-16 13:12:46 UTC
  • mfrom: (169.1.22 release-2014-06-12)
  • Revision ID: ps-jenkins@lists.canonical.com-20140616131246-rzqpkq95ut0j8gka
Implemented contact share.
Replaced ContentHub API with QML API.
Removed ContactSearchListView component.
Moved ContactSimpleListView to the private API.
Added documentation for ContactListView properties.
Created "contactNameFilter" into ContactListView.
Update contact list visuals.
Implemented fast scroll.
Implemented contact search.
Initial refactor of autopilot tests.
Used new SDK header. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Copyright (C) 2014 Canonical Ltd.
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
2
16
 
3
17
""" ContactListPage emulator for Addressbook App tests """
4
18
 
5
 
# Copyright 2014 Canonical
6
 
#
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.
10
 
 
11
19
import logging
 
20
import time
12
21
 
13
22
from autopilot.introspection.dbus import StateNotFoundError
14
 
from ubuntuuitoolkit import emulators as uitk
 
23
 
 
24
from address_book_app.pages import _common, _contact_view
 
25
 
15
26
 
16
27
LOGGER = logging.getLogger(__name__)
17
 
from time import sleep
18
 
 
19
 
 
20
 
class ContactListPage(uitk.UbuntuUIToolkitEmulatorBase):
 
28
 
 
29
 
 
30
class ContactListPage(_common.PageWithHeader, _common.PageWithBottomEdge):
21
31
    """ ContactListPage emulator class """
22
32
 
23
33
    def __init__(self, *args):
26
36
        self.selected_marks = []
27
37
        super(ContactListPage, self).__init__(*args)
28
38
 
 
39
    def open_contact(self, index):
 
40
        """Open the page with the contact information.
 
41
 
 
42
        :param index: The index of the contact to open.
 
43
        :return: The page with the contact information.
 
44
 
 
45
        """
 
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')
 
55
 
 
56
    def _get_list_view(self):
 
57
        return self.wait_select_single("ContactListView",
 
58
                                       objectName="contactListView")
 
59
 
29
60
    def get_contacts(self):
30
61
        """
31
62
        Returns a list of ContactDelegate objects and populate
32
63
        self.selection_marks
33
64
        """
34
 
        sleep(1)
 
65
        time.sleep(1)
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
43
74
 
 
75
    def start_selection(self, idx):
 
76
        view = self._get_list_view()
 
77
        if not view.isInSelectionMode:
 
78
            self.get_contacts()
 
79
            self.selected_marks.append(self.selection_marks[idx])
 
80
            self.pointing_device.move_to_object(self.contacts[idx])
 
81
            self.pointing_device.press()
 
82
            time.sleep(2.0)
 
83
            self.pointing_device.release()
 
84
            view.isInSelectionMode.wait_for(True)
 
85
        else:
 
86
            self.selected_marks.append(self.selection_marks[idx])
 
87
            self.pointing_device.click_object(self.selection_marks[idx])
 
88
 
 
89
 
44
90
    def select_contacts_by_index(self, indices):
45
91
        """ Select contacts corresponding to the list of index in indices
46
92
 
47
93
        :param indices: List of integers
48
94
        """
49
95
        self.deselect_all()
 
96
        if len(indices) > 0:
 
97
            self.start_selection(indices[0])
50
98
 
51
 
        # Select matching indices
52
 
        for idx in 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])
55
103
 
56
104
    def deselect_all(self):
57
105
        """Deselect every contacts"""
63
111
                                             objectName="selectionMark")
64
112
                self.pointing_device.click_object(mark)
65
113
 
66
 
    def click_button(self, objectname):
 
114
    def click_button(self, parent, objectname):
67
115
        """Press a button that matches objectname
68
116
 
69
117
        :param objectname: Name of the object
70
118
        """
 
119
        if parent:
 
120
            obj = parent
 
121
        else:
 
122
            obj = self
71
123
        try:
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:
80
132
            )
81
133
            raise
82
134
 
83
 
    def cancel(self):
84
 
        """Press the cancel button displayed when pick mode is enabled"""
85
 
        self.click_button("DialogButtons.rejectButton")
86
 
 
87
 
    def delete(self):
88
 
        """Press the delete button displayed when pick mode is enabled"""
89
 
        self.click_button("DialogButtons.acceptButton")
90
 
        self.get_contacts()
 
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")