Exemplo n.º 1
0
    def click_action_button(self, action_object_name):
        """Click an action button on the popover.

        :parameter object_name: The QML objectName property of the action
        :raise ToolkitException: If there is no visible button with that object
            name or the popover is not open.

        """

        if not self.visible:
            raise _common.ToolkitException('The popover is not open.')
        try:
            object_name = action_object_name + "_button"
            button = self.select_single(objectName=object_name)
        except dbus.StateNotFoundError:
            raise _common.ToolkitException(
                'Button for action with objectName "{0}" not found.'.format(
                    action_object_name))
        if not button.visible:
            raise _common.ToolkitException(
                'Button for action with objectName "{0}" not visible.'.format(
                    action_object_name))
        self.pointing_device.click_object(button)
        if self.autoClose:
            try:
                self.visible.wait_for(False)
            except dbus.StateNotFoundError:
                # The popover was removed from the tree.
                pass
Exemplo n.º 2
0
    def switch_to_section_by_index(self, index):
        """Select a section in the header divider

        :parameter index: The index of the section to select
        :raise ToolkitEmulatorException: If the selection index is out of
                range or useDeprecatedToolbar is set.

        """
        self.ensure_visible()

        if self.useDeprecatedToolbar:
            raise _common.ToolkitException('Old header has no sections')

        self.wait_for_animation()
        try:
            # Ubuntu.Components >=1.3
            sections = self.select_single('Sections',
                                          objectName='headerSectionsItem')
            sections.click_section_button(index)
        except dbus.StateNotFoundError:
            # Ubuntu.Components < 1.3, has no headerSectionsItem.
            try:
                object_name = "section_button_" + str(index)
                button = self.select_single(objectName=object_name)
            except dbus.StateNotFoundError:
                raise _common.ToolkitException(
                    'Button for section with given index not found')

            self.pointing_device.click_object(button)
Exemplo n.º 3
0
    def _switch_to_tab_in_drawer_by_index(self, index):
        self.wait_for_animation()
        try:
            tabs_drawer_button = self.select_single(objectName='tabsButton')
        except dbus.StateNotFoundError:
            raise _common.ToolkitException(_NO_TABS_ERROR)
        self.pointing_device.click_object(tabs_drawer_button)

        tabs_model_properties = self.select_single(
            'QQuickItem', objectName='tabsModelProperties')

        if tabs_model_properties.selectedIndex == index:
            return

        popover = self.get_root_instance().select_single(
            objectName='tabsPopover')

        try:
            # 1.3, using ActionSelectionPopover
            action_name = 'select_tab_' + str(index)
            popover.click_action_button(action_name)
        except _common.ToolkitException:
            try:
                # < 1.3 using custom popover
                tab_button = self.get_root_instance().select_single(
                    objectName='tabButton' + str(index))
                self.pointing_device.click_object(tab_button)
            except dbus.StateNotFoundError:
                raise _common.ToolkitException(
                    "Tab button {0} not found.".format(index))

        self.wait_for_animation()
Exemplo n.º 4
0
    def click_option_by_text(self, text):
        """Click a button on the popover.

        XXX We are receiving the text because there's no way to set the
        objectName on the action. This is reported at
        https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1205144
        --elopio - 2013-07-25

        :parameter text: The text of the button.
        :raise ToolkitException: If the popover is not open.

        """
        if not self.visible:
            raise _common.ToolkitException('The popover is not open.')
        button = self._get_button(text)
        if button is None:
            raise _common.ToolkitException(
                'Button with text "{0}" not found.'.format(text))
        self.pointing_device.click_object(button)
        if self.autoClose:
            try:
                self.visible.wait_for(False)
            except dbus.StateNotFoundError:
                # The popover was removed from the tree.
                pass
Exemplo n.º 5
0
    def click_button(self, object_name):
        """Click a button of the toolbar.

        The toolbar should be opened before clicking the button, or an
        exception will be raised. If the toolbar is closed for some reason
        (e.g., timer finishes) after moving the mouse cursor and before
        clicking the button, it is re-opened automatically by this function.

        :parameter object_name: The QML objectName property of the button.
        :raise ToolkitException: If there is no button with that object
            name.

        """
        # ensure the toolbar is open
        if not self.opened:
            raise _common.ToolkitException(
                'Toolbar must be opened before calling click_button().')
        try:
            button = self._get_button(object_name)
        except dbus.StateNotFoundError:
            raise _common.ToolkitException(
                'Button with objectName "{0}" not found.'.format(object_name))
        self.pointing_device.move_to_object(button)
        # ensure the toolbar is still open (may have closed due to timeout)
        self.open()
        # click the button
        self.pointing_device.click_object(button)
Exemplo n.º 6
0
    def _swipe_to_delete_removable_item(self, direction):
        if direction == 'left':
            raise _common.ToolkitException(
                'Only swiping to the right will cause the item to be deleted.')
        elif direction != 'right':
            raise _common.ToolkitException(
                'Invalid direction "{0}" used on swipe to delete function'.
                format(direction))

        self._drag_pointing_device_to_delete()
        if self.confirmRemoval:
            self.waitingConfirmationForRemoval.wait_for(True)
        else:
            self._wait_until_deleted()
Exemplo n.º 7
0
    def click_back_button(self):
        self.ensure_visible()

        if self.useDeprecatedToolbar:
            raise _common.ToolkitException('Old header has no back button')
        try:
            self.wait_for_animation()
            back_button = self.select_single(objectName='backButton')
        except dbus.StateNotFoundError:
            raise _common.ToolkitException('Missing back button in header')
        if not back_button.visible:
            raise _common.ToolkitException('Back button in header not visible')
        self.pointing_device.click_object(back_button)
        self.wait_for_animation()
Exemplo n.º 8
0
    def pick_time(self, time):
        """Pick a time from the date picker.

        :parameter time: The time to pick.
        :type time: An object with hour, minute and second attributes, like
            python's datetime.time.
        :raises ubuntuuitoolkit.ToolkitException if the mode of the picker
            doesn't let select a time.

        """
        if not self._is_time_picker():
            raise _common.ToolkitException(
                "Can't pick time. The picker mode is: {!r}.".format(self.mode))
        # Workaround https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1346669
        # By setting seconds, then minutes, then hours, erratic behavoir
        # can be dealt with
        if 'Seconds' in self.mode:
            self._pick_second(time.second)
            self.seconds.wait_for(time.second)
        if 'Minutes' in self.mode:
            self._pick_minute(time.minute)
            self.minutes.wait_for(time.minute)
        if 'Hours' in self.mode:
            self._pick_hour(time.hour)
            self.hours.wait_for(time.hour)
Exemplo n.º 9
0
    def click_action_button(self, action_object_name):
        """Click an action button of the header.

        :parameter object_name: The QML objectName property of the action
        :raise ToolkitException: If there is no action button with that object
            name.

        """
        self.ensure_visible()

        try:
            # for Ubuntu.Components 1.3
            actionbar = self.select_single('ActionBar',
                                           objectName='headerActionBar')
            actionbar.click_action_button(action_object_name)
        except dbus.StateNotFoundError:
            # for Ubuntu.Components < 1.3
            button = self._get_action_button(action_object_name)
            # In an animating header, the button is disabled until the header
            #   animation is done. Wait for that:
            button.enabled.wait_for(True)
            self.pointing_device.click_object(button)
        except _common.ToolkitException:
            # Catch 'Button not found in ActionBar or overflow' exception
            raise _common.ToolkitException(
                'Button not found in header or overflow')

        self.wait_for_animation()
Exemplo n.º 10
0
 def _switch_to_next_tab_in_deprecated_tabbar(self):
     try:
         tab_bar = self.select_single(_tabbar.TabBar)
     except dbus.StateNotFoundError:
         raise _common.ToolkitException(_NO_TABS_ERROR)
     tab_bar.switch_to_next_tab()
     self._get_animating().wait_for(False)
Exemplo n.º 11
0
 def _get_tab_button(self, index):
     buttons = self._get_tab_buttons()
     for button in buttons:
         if button.buttonIndex == index:
             return button
     raise _common.ToolkitException(
         'There is no tab button with index {0}.'.format(index))
Exemplo n.º 12
0
    def _find_element(self, object_name, direction=None):
        if direction is None:
            # We don't know where the object is so we start looking for it from
            # the top or left, depending on the ListView orientation.
            if self.orientation == 2:
                # 2 == ListView.Vertical
                self.swipe_to_top()
                direction = 'below'
            else:
                # orientation == 1 == ListView.Horizontal
                self.swipe_to_leftmost()
                direction = 'right'

        if direction == 'below':
            def fail_condition():
                return self.atYEnd
            swipe_method = self.swipe_to_show_more_below
        elif direction == 'above':
            def fail_condition():
                return self.atYBeginning
            swipe_method = self.swipe_to_show_more_above
        elif direction == 'left':
            def fail_condition():
                return self.atXBeginning
            swipe_method = self.swipe_to_show_more_left
        elif direction == 'right':
            def fail_condition():
                return self.atXEnd
            swipe_method = self.swipe_to_show_more_right
        else:
            raise _common.ToolkitException(
                'Invalid direction: {}'.format(direction))

        containers = self._get_containers()
        while not fail_condition():
            try:
                return self.select_single(objectName=object_name)
            except dbus.StateNotFoundError:
                swipe_method(containers)
        else:
            # We have reached the start or the end of the list.
            try:
                return self.select_single(objectName=object_name)
            except dbus.StateNotFoundError:
                raise _common.ToolkitException(
                    'List element with objectName "{}" not found.'.format(
                        object_name))
Exemplo n.º 13
0
 def _get_tab(self, index):
     tabs = self._get_tabs()
     for tab in tabs:
         if tab.index == index:
             return tab
     else:
         raise _common.ToolkitException(
             'There is no tab with index {0}.'.format(index))
Exemplo n.º 14
0
    def _switch_to_tab_in_drawer_by_index(self, index):
        tabs = self.get_tabs()
        number_of_tabs = tabs.get_number_of_tabs()
        if index >= number_of_tabs:
            raise _common.ToolkitException('Tab index out of range.')

        if index != tabs.selectedTabIndex:
            self.get_header().switch_to_tab_by_index(index)
        current_tab = tabs.get_current_tab()
        return current_tab
Exemplo n.º 15
0
    def _find_element(self, object_name, direction):
        containers = self._get_containers()
        for index in range(self.count):
            if direction == 'below':
                swipe_method = self._swipe_to_show_one_more_below
            elif direction == 'above':
                swipe_method = self._swipe_to_show_one_more_above
            else:
                raise _common.ToolkitException(
                    'Invalid direction: {}'.format(direction))

            swipe_method(containers)

            try:
                return self.select_single(objectName=object_name)
            except dbus.StateNotFoundError:
                pass
        raise _common.ToolkitException(
            'List element with objectName "{}" not found.'.format(object_name))
Exemplo n.º 16
0
 def confirm_removal(self):
     """Comfirm item removal if this was already swiped."""
     if self.waitingConfirmationForRemoval:
         deleteButton = self._get_confirm_button()
         self.pointing_device.click_object(deleteButton)
         self._wait_until_deleted()
     else:
         raise _common.ToolkitException(
             'The item "{0}" is not waiting for removal confirmation'.
             format(self.objectName))
Exemplo n.º 17
0
    def get_tabs(self):
        """Return the Tabs custom proxy object of the MainView.

        :raise ToolkitException: If the main view has no tabs.

        """
        try:
            return self.select_single(_tabs.Tabs)
        except dbus.StateNotFoundError:
            raise _common.ToolkitException(_NO_TABS_ERROR)
Exemplo n.º 18
0
 def _switch_to_next_tab_in_drawer(self):
     self.wait_for_animation()
     tabs_model_properties = self.select_single(
         'QQuickItem', objectName='tabsModelProperties')
     if tabs_model_properties.count == 0:
         raise _common.ToolkitException(_NO_TABS_ERROR)
     next_tab_index =\
         (tabs_model_properties.selectedIndex + 1)\
         % tabs_model_properties.count
     self._switch_to_tab_in_drawer_by_index(next_tab_index)
Exemplo n.º 19
0
    def _switch_to_tab_in_deprecated_tabbar_by_index(self, index):
        tabs = self.get_tabs()
        number_of_tabs = tabs.get_number_of_tabs()
        if index >= number_of_tabs:
            raise _common.ToolkitException('Tab index out of range.')

        current_tab = tabs.get_current_tab()
        number_of_switches = 0
        while not tabs.selectedTabIndex == index:
            logger.debug('Current tab index: {0}.'.format(
                tabs.selectedTabIndex))
            if number_of_switches >= number_of_tabs - 1:
                # This prevents a loop. But if this error is ever raised, it's
                # likely there's a bug on the helper or on the QML Tab.
                raise _common.ToolkitException(
                    'The tab with index {0} was not selected.'.format(index))
            current_tab = self.switch_to_next_tab()
            number_of_switches += 1
        return current_tab
Exemplo n.º 20
0
    def get_toolbar(self):
        """Return the Toolbar custom proxy object of the MainView.

        :raise ToolkitException: If the main view has no toolbar.

        """
        try:
            return self.select_single(_toolbar.Toolbar)
        except dbus.StateNotFoundError:
            raise _common.ToolkitException(_NO_TOOLBAR_ERROR)
Exemplo n.º 21
0
    def _open_overflow(self):
        """Click the overflow button and return the overflow panel"""
        actions_overflow_button = self.select_single(
            objectName='overflow_action_button')

        if not actions_overflow_button.visible:
            raise _common.ToolkitException('No actions in overflow')

        # open the popover
        self.pointing_device.click_object(actions_overflow_button)

        # the popover is not a child of the ActionBar, so use the popover
        # object to find the requested button
        try:
            popover = self.get_root_instance().select_single(
                objectName='actions_overflow_panel')
        except dbus.StateNotFoundError:
            raise _common.ToolkitException('Failed to select overflow panel')

        return popover
Exemplo n.º 22
0
    def click_button_by_text(self, text):
        """Click a button on the popover.

        :parameter text: The text of the button.
        :raise ToolkitException: If there is no visible button with that label
            or the popover is not open.

        """
        if not self.visible:
            raise _common.ToolkitException('The popover is not open.')
        button = self._get_button(text)
        if button is None:
            raise _common.ToolkitException(
                'Button with text "{0}" not found.'.format(text))
        self.pointing_device.click_object(button)
        if self.autoClose:
            try:
                self.visible.wait_for(False)
            except dbus.StateNotFoundError:
                # The popover was removed from the tree.
                pass
Exemplo n.º 23
0
    def click_action_button(self, action_object_name):
        """Click the specified button.

        :parameter action_object_name: the objectName of the action to trigger.
        :raise ToolkitException: The requested button is not available.

        """
        if self.useDeprecatedToolbar:
            raise _common.ToolkitException(
                "App is using deprecated toolbar instead of new header")
        else:
            header = self.open_header()
            header.click_action_button(action_object_name)
Exemplo n.º 24
0
    def click_section_button(self, section_index):
        """Click a section button of the Sections.

        :parameter section_index: The index of the section to click.
        :raise ToolkitException: If there is no section button with that index.

        """
        button_object_name = 'section_button_' + str(section_index)
        try:
            self.listview.click_element(button_object_name)
        except _common.ToolkitException:
            raise _common.ToolkitException('Button with section index ' +
                                           str(section_index) +
                                           ' not found in Sections.')
Exemplo n.º 25
0
 def _scrolling_bar_click_action_button(self, action_object_name):
     buttonName = action_object_name + "_button"
     try:
         self.listview.click_element(buttonName)
     except _flickable.CannotSwipeMoreToolkitException:
         # The button was found, but is not inside the ListView. This
         # happens because at the beginning and end of the ListView
         # there are list items visible inside the extra margins. But
         # the buttons are present otherwise a different error message
         # wass given.
         button = self.listview.select_single(objectName=buttonName)
         self.pointing_device.click_object(button)
     except _common.ToolkitException:
         raise _common.ToolkitException('Button not found')
Exemplo n.º 26
0
 def enable_select_mode(self):
     """Default implementation to enable select mode. Performs a long tap
        over the first list item in the ListView. The delegates must be
        the new ListItem components.
     """
     self.swipe_to_top()
     first_item = self._get_first_item()
     self.pointing_device.click_object(first_item, press_duration=2)
     try:
         self.wait_select_single('QQuickItem',
                                 objectName='selection_panel0')
     except dbus.StateNotFoundError:
         raise _common.ToolkitException(
             'ListView delegate is not a ListItem or not in selectMode')
Exemplo n.º 27
0
    def _get_action_button_in_overflow(self, action_object_name):
        actions_overflow_button = self.select_single(
            objectName='actions_overflow_button')

        if not actions_overflow_button.visible:
            raise _common.ToolkitException('No actions in overflow')

        # open the popover
        self.pointing_device.click_object(actions_overflow_button)
        object_name = action_object_name + "_header_overflow_button"

        # the popover is not a child of the header, so use the root object
        # to find the requested button
        return self.get_root_instance().select_single(objectName=object_name)
Exemplo n.º 28
0
    def _slow_drag(self, start_x, stop_x, start_y, stop_y, rate=None):
        # If we drag too fast, we end up scrolling more than what we
        # should, sometimes missing the  element we are looking for.

        # FIXME: QQuickPathView has no contentY property, but it was added
        # to the PathView used inside the Picker in Picker.qml
        original_content_y = self.contentY

        if rate is None:
            rate = self._slow_drag_rate()
        self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate=rate)

        if self.contentY == original_content_y:
            raise _common.ToolkitException('Could not swipe in the flickable.')
Exemplo n.º 29
0
    def switch_to_tab(self, object_name):
        """Open a tab.

        :parameter object_name: The QML objectName property of the tab.
        :return: The newly opened tab.
        :raise ToolkitException: If there is no tab with that object
            name.

        """
        tabs = self.get_tabs()
        for index, tab in enumerate(tabs.select_many('Tab')):
            if tab.objectName == object_name:
                return self.switch_to_tab_by_index(tab.index)
        raise _common.ToolkitException(
            'Tab with objectName "{0}" not found.'.format(object_name))
Exemplo n.º 30
0
    def click_action_button(self, action_object_name):
        """Click an action button of the action bar.

        :parameter object_name: The QML objectName property of the action
        :raise ToolkitException: If there is no action button with that object
            name.

        """
        if self.styleName == "ActionBarStyle":
            return self._overflow_bar_click_action_button(action_object_name)
        elif self.styleName == "ScrollingActionBarStyle":
            return self._scrolling_bar_click_action_button(action_object_name)
        else:
            raise _common.ToolkitException('Unsupported style name ' +
                                           self.styleName + ' for ActionBar.')