예제 #1
0
    def __init__(self, marionette_getter, window, element):
        UIBaseLib.__init__(self, marionette_getter, window, element)

        self._security = Security(lambda: self.marionette)
        self._handle = None
예제 #2
0
    def __init__(self, marionette, window, element):
        super(Tab, self).__init__(marionette, window, element)

        self._security = Security(self.marionette)
        self._handle = None
예제 #3
0
class Tab(UIBaseLib):
    """Wraps a tab DOM element."""

    def __init__(self, marionette_getter, window, element):
        UIBaseLib.__init__(self, marionette_getter, window, element)

        self._security = Security(lambda: self.marionette)
        self._handle = None

    # Properties for visual elements of tabs #

    @property
    def close_button(self):
        """The DOM element which represents the tab close button.

        :returns: Reference to the tab close button.
        """
        return self.tab_element.find_element(By.ANON_ATTRIBUTE, {'anonid': 'close-button'})

    @property
    def tab_element(self):
        """The inner tab DOM element.

        :returns: Tab DOM element.
        """
        return self.element

    # Properties for backend values

    @property
    def location(self):
        """Returns the current URL

        :returns: Current URL
        """
        self.switch_to()

        return self.marionette.execute_script("""
          return arguments[0].linkedBrowser.currentURI.spec;
        """, script_args=[self.tab_element])

    @property
    def certificate(self):
        """The SSL certificate assiciated with the loaded web page.

        :returns: Certificate details as JSON blob.
        """
        self.switch_to()

        return self._security.get_certificate_for_page(self.tab_element)

    # Properties for helpers when working with tabs #

    @property
    def handle(self):
        """The `handle` of the content window.

        :returns: content window `handle`.
        """
        # If no handle has been set yet, wait until it is available
        if not self._handle:
            self._handle = Wait(self.marionette).until(
                lambda mn: TabBar.get_handle_for_tab(mn, self.element),
                message='Tab handle could not be found.')

        return self._handle

    @property
    def selected(self):
        """Checks if the tab is selected.

        :return: `True` if the tab is selected.
        """
        return self.marionette.execute_script("""
            return arguments[0].hasAttribute('selected');
        """, script_args=[self.tab_element])

    # Methods for helpers when working with tabs #

    def __eq__(self, other):
        return self.handle == other.handle

    def close(self, trigger='menu', force=False):
        """Closes the tab by using the specified trigger.

        When the tab is closed a :func:`switch_to` call is automatically performed, so that
        the new selected tab becomes active.

        :param trigger: Optional, method in how to close the tab. This can
         be a string with one of `button`, `menu` or `shortcut`, or a callback which
         gets triggered with the current :class:`Tab` as parameter. Defaults to `menu`.

        :param force: Optional, forces the closing of the window by using the Gecko API.
         Defaults to `False`.
        """
        handle = self.handle
        start_handles = self.marionette.window_handles

        self.switch_to()

        if force:
            self.marionette.close()
        elif callable(trigger):
            trigger(self)
        elif trigger == 'button':
            self.close_button.click()
        elif trigger == 'menu':
            self.window.menubar.select_by_id('file-menu', 'menu_close')
        elif trigger == 'shortcut':
            self.window.send_shortcut(self.window.get_entity('closeCmd.key'), accel=True)
        else:
            raise ValueError('Unknown closing method: "%s"' % trigger)

        Wait(self.marionette).until(
            lambda _: len(self.window.tabbar.tabs) == len(start_handles) - 1,
            message='Tab with handle "%s" has not been closed.' % handle)

        # Ensure to switch to the window handle which represents the new selected tab
        self.window.tabbar.selected_tab.switch_to()

    def select(self):
        """Selects the tab and sets the focus to it."""
        self.tab_element.click()
        self.switch_to()

        # Bug 1121705: Maybe we have to wait for TabSelect event
        Wait(self.marionette).until(
            lambda _: self.selected,
            message='Tab with handle "%s" could not be selected.' % self.handle)

    def switch_to(self):
        """Switches the context of Marionette to this tab.

        Please keep in mind that calling this method will not select the tab.
        Use the :func:`~Tab.select` method instead.
        """
        self.marionette.switch_to_window(self.handle)
예제 #4
0
    def __init__(self, marionette, window, element):
        super(Tab, self).__init__(marionette, window, element)

        self._security = Security(self.marionette)
        self._handle = None