コード例 #1
0
    def close(self, callback=None, force=False):
        """Closes the current chrome window.

        If this is the last remaining window, the marionette session is ended.

        :param callback: Optional, function to trigger the window to open. It is
         triggered with the current :class:`BaseWindow` as parameter.
         Defaults to `window.open()`

        :param force: Optional, forces the closing of the window by using the Gecko API.
         Defaults to `False`.
        """
        self.switch_to()

        # Bug 1121698
        # For more stable tests register an observer topic first
        prev_win_count = len(self.marionette.chrome_window_handles)

        if self.handle != self.marionette.current_chrome_window_handle:
            self.switch_to()

        if force or callback is None:
            self._windows.close(self.handle)
        else:
            callback(self)

        # Bug 1121698
        # Observer code should let us ditch this wait code
        wait = Wait(self.marionette)
        wait.until(
            lambda m: len(m.chrome_window_handles) == prev_win_count - 1)

        # Ensure we wait long enough until the window has been fully loaded
        sleep(.5)
コード例 #2
0
    def focus(self, handle):
        """Focuses the chrome window with the given handle.

        :param handle: The handle of the chrome window
        """
        self.switch_to(handle)

        with self.marionette.using_context('chrome'):
            self.marionette.execute_script(""" window.focus(); """)

        wait = Wait(self.marionette)
        wait.until(lambda m: handle == self.focused_chrome_window_handle)