~elopio/ubuntu-filemanager-app/fix1188732-test_open_directory

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py

  • Committer: Leo Arias
  • Date: 2013-06-14 05:20:24 UTC
  • Revision ID: leo.arias@canonical.com-20130614052024-0sj6r1usaoln7jzn
Added the ubuntusdk emulator. Test is now working.

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
# Copyright (C) 2013 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
 
7
# published 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/>.
 
16
#
 
17
# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
 
18
 
 
19
from testtools.matchers import Equals, NotEquals, Not, Is
 
20
from autopilot.matchers import Eventually
 
21
 
 
22
class ubuntusdk(object):
 
23
    """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
 
24
 
 
25
    def __init__(self, autopilot, app):
 
26
        self.app = app
 
27
        self.autopilot = autopilot
 
28
 
 
29
    def get_qml_view(self):
 
30
        """Get the main QML view"""
 
31
        return self.app.select_single("QQuickView")
 
32
 
 
33
    def get_object(self, typeName, name):
 
34
        """Get a specific object"""
 
35
        return self.app.select_single(typeName, objectName=name)
 
36
 
 
37
    def get_objects(self, typeName, name):
 
38
        """Get more than one object"""
 
39
        return self.app.select_many(typeName, objectName=name)
 
40
 
 
41
    def switch_to_tab(self, tab):
 
42
        """Switch to the specified tab number"""
 
43
        tabs = self.get_tabs()
 
44
        currentTab = tabs.selectedTabIndex
 
45
 
 
46
        #perform operations until tab == currentTab
 
47
        while tab != currentTab:
 
48
            if tab > currentTab:
 
49
                self._previous_tab()
 
50
            if tab < currentTab:
 
51
                self._next_tab()
 
52
            currentTab = tabs.selectedTabIndex
 
53
 
 
54
    def toggle_toolbar(self):
 
55
        """Toggle the toolbar between revealed and hidden"""
 
56
        #check and see if the toolbar is open or not
 
57
        if self.get_toolbar().opened:
 
58
            self.hide_toolbar()
 
59
        else:
 
60
            self.open_toolbar()
 
61
 
 
62
    def get_toolbar(self):
 
63
        """Returns the toolbar in the main events view."""
 
64
        return self.app.select_single("Toolbar")
 
65
 
 
66
    def get_toolbar_button(self, buttonLabel):
 
67
        """Returns the toolbar button at position index"""
 
68
        toolbar = self.get_toolbar()
 
69
        if not toolbar.opened:
 
70
            self.open_toolbar()
 
71
        row = toolbar.select_single("QQuickRow")
 
72
        loaderList = row.select_many("QQuickLoader")
 
73
        for loader in loaderList:
 
74
            buttonList = loader.select_many("Button")
 
75
            for button in buttonList:
 
76
                if button.text == buttonLabel:
 
77
                    return button
 
78
 
 
79
    def click_toolbar_button(self, buttonLabel):
 
80
        """Clicks the toolbar button with buttonLabel"""
 
81
        #The toolbar button is assumed to be the following format
 
82
        #ToolbarActions {
 
83
        #           Action {
 
84
        #               objectName: "name"
 
85
        #                text: value
 
86
        button = self.get_toolbar_button(buttonLabel)
 
87
        self.autopilot.pointing_device.click_object(button)
 
88
 
 
89
    def open_toolbar(self):
 
90
        """Open the toolbar"""
 
91
        qmlView = self.get_qml_view()
 
92
 
 
93
        lineX = qmlView.x + qmlView.width * 0.50
 
94
        startY = qmlView.y + qmlView.height - 1
 
95
        stopY = qmlView.y + qmlView.height * 0.95
 
96
 
 
97
        self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
 
98
 
 
99
    def hide_toolbar(self):
 
100
        """Hide the toolbar"""
 
101
        qmlView = self.get_qml_view()
 
102
 
 
103
        lineX = qmlView.x + qmlView.width * 0.50
 
104
        startY = qmlView.y + qmlView.height * 0.95
 
105
        stopY = qmlView.y + qmlView.height - 1
 
106
 
 
107
        self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
 
108
 
 
109
    def set_popup_value(self, popover, button, value):
 
110
        """Changes the given popover selector to the request value
 
111
        At the moment this only works for values that are currently visible. To
 
112
        access the remaining items, a help method to drag and recheck is needed."""
 
113
        #The popover is assumed to be the following format
 
114
        #    Popover {
 
115
        #        Column {
 
116
        #            ListView {
 
117
        #                delegate: Standard {
 
118
        #                    objectName: "name"
 
119
        #                    text: value
 
120
 
 
121
        self.autopilot.pointing_device.click_object(button)
 
122
        #we'll get all matching objects, incase the popover is reused between buttons
 
123
        itemList = lambda: self.get_objects("Standard", popover)
 
124
 
 
125
        for item in itemList():
 
126
            if item.get_properties()['text'] == value:
 
127
                self.autopilot.pointing_device.click_object(item)
 
128
 
 
129
    def get_tabs(self):
 
130
        """Return all tabs"""
 
131
        return self.get_object("Tabs", "rootTabs")
 
132
 
 
133
    def _previous_tab(self):
 
134
        """Switch to the previous tab"""
 
135
        qmlView = self.get_qml_view()
 
136
 
 
137
        startX = qmlView.x + qmlView.width * 0.35
 
138
        stopX = qmlView.x + qmlView.width * 0.50
 
139
        lineY = qmlView.y + qmlView.height * 0.05
 
140
 
 
141
        self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
 
142
        self.autopilot.pointing_device.click()
 
143
        self.autopilot.pointing_device.click()
 
144
 
 
145
    def _next_tab(self):
 
146
        """Switch to the next tab"""
 
147
        qmlView = self.get_qml_view()
 
148
 
 
149
        startX = qmlView.x + qmlView.width * 0.50
 
150
        stopX = qmlView.x + qmlView.width * 0.35
 
151
        lineY = qmlView.y + qmlView.height * 0.05
 
152
 
 
153
        self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
 
154
        self.autopilot.pointing_device.click()