~timo-jyrinki/address-book-app/rebuild_against_qt521

« back to all changes in this revision

Viewing changes to tests/autopilot/address_book_app/emulators/contact_list_page.py

  • Committer: CI bot
  • Author(s): Jean-Baptiste Lallement
  • Date: 2014-02-27 02:29:20 UTC
  • mfrom: (134.2.4 abook.tc_delete)
  • Revision ID: ps-jenkins@lists.canonical.com-20140227022920-7bbjk3i13ymdlw67
tests/autopilot: Added 'delete contact' test case with pick mode enabled 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
 
 
3
""" ContactListPage emulator for Addressbook App tests """
 
4
 
 
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
import logging
 
12
 
 
13
from autopilot.introspection.dbus import StateNotFoundError
 
14
from ubuntuuitoolkit import emulators as uitk
 
15
 
 
16
LOGGER = logging.getLogger(__name__)
 
17
from time import sleep
 
18
 
 
19
 
 
20
class ContactListPage(uitk.UbuntuUIToolkitEmulatorBase):
 
21
    """ ContactListPage emulator class """
 
22
 
 
23
    def __init__(self, *args):
 
24
        self.contacts = None
 
25
        self.selection_marks = []
 
26
        self.selected_marks = []
 
27
        super(ContactListPage, self).__init__(*args)
 
28
 
 
29
    def get_contacts(self):
 
30
        """
 
31
        Returns a list of ContactDelegate objects and populate
 
32
        self.selection_marks
 
33
        """
 
34
        sleep(1)
 
35
        self.contacts = self.select_many("ContactDelegate")
 
36
        self.selection_marks = []
 
37
        for contact in self.contacts:
 
38
            if contact.visible:
 
39
                mark = contact.select_single("QQuickRectangle",
 
40
                                             objectName="selectionMark")
 
41
            self.selection_marks.append(mark)
 
42
        return self.contacts
 
43
 
 
44
    def select_contacts_by_index(self, indices):
 
45
        """ Select contacts corresponding to the list of index in indices
 
46
 
 
47
        :param indices: List of integers
 
48
        """
 
49
        self.deselect_all()
 
50
 
 
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])
 
55
 
 
56
    def deselect_all(self):
 
57
        """Deselect every contacts"""
 
58
        contacts = self.select_many("ContactDelegate")
 
59
        self.selected_marks = []
 
60
        for contact in contacts:
 
61
            if contact.selected:
 
62
                mark = contact.select_single("QQuickRectangle",
 
63
                                             objectName="selectionMark")
 
64
                self.pointing_device.click_object(mark)
 
65
 
 
66
    def click_button(self, objectname):
 
67
        """Press a button that matches objectname
 
68
 
 
69
        :param objectname: Name of the object
 
70
        """
 
71
        try:
 
72
            buttons = self.select_many("Button",
 
73
                                       objectName=objectname)
 
74
            for button in buttons:
 
75
                if button.visible:
 
76
                    self.pointing_device.click_object(button)
 
77
        except StateNotFoundError:
 
78
            LOGGER.error(
 
79
                'Button with objectName "{0}" not found.'.format(objectname)
 
80
            )
 
81
            raise
 
82
 
 
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()