def close(self, trigger='shortcut', force=False): """Closes the current page info window by using the specified trigger. :param trigger: Optional, method to close the current window. This can be a string with one of `menu` (OS X only) or `shortcut`, or a callback which gets triggered with the current :class:`PageInfoWindow` as parameter. Defaults to `shortcut`. :param force: Optional, forces the closing of the window by using the Gecko API. Defaults to `False`. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': # TODO: Make use of menubar class once it supports ids menu = win.marionette.find_element(By.ID, 'menu_closeWindow') menu.click() elif trigger == 'shortcut': win.send_shortcut(win.get_entity('closeWindow.key'), accel=True) else: raise ValueError('Unknown closing method: "%s"' % trigger) BaseWindow.close(self, callback, force)
def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) self._navbar = None self._tabbar = None # Timeout for loading remote web pages self.timeout_page_load = 30
def open_browser(self, trigger='menu', is_private=False): """Opens a new browser window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :param is_private: Optional, if True the new window will be a private browsing one. :returns: :class:`BrowserWindow` instance for the new browser window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': menu_id = 'menu_newPrivateWindow' if is_private else 'menu_newNavigator' self.menubar.select_by_id('file-menu', menu_id) elif trigger == 'shortcut': cmd_key = 'privateBrowsingCmd.commandkey' if is_private else 'newNavigatorCmd.key' win.send_shortcut(win.localize_entity(cmd_key), accel=True, shift=is_private) else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, BrowserWindow)
def open_page_info_window(self, trigger='menu'): """Opens the page info window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :returns: :class:`PageInfoWindow` instance of the opened window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': self.menubar.select_by_id('tools-menu', 'menu_pageInfo') elif trigger == 'shortcut': if win.marionette.session_capabilities['platform'] == 'WINDOWS_NT': raise ValueError('Page info shortcut not available on Windows.') win.send_shortcut(win.get_entity('pageInfoCmd.commandkey'), accel=True) elif trigger == 'context_menu': # TODO: Add once we can do right clicks pass else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, PageInfoWindow)
def open_browser(self, trigger='menu', is_private=False): """Opens a new browser window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :param is_private: Optional, if True the new window will be a private browsing one. :returns: :class:`BrowserWindow` instance for the new browser window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': menu_id = 'menu_newPrivateWindow' if is_private else 'menu_newNavigator' self.menubar.select_by_id('file-menu', menu_id) elif trigger == 'shortcut': cmd_key = 'privateBrowsingCmd.commandkey' if is_private else 'newNavigatorCmd.key' win.send_shortcut(win.get_entity(cmd_key), accel=True, shift=is_private) else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, BrowserWindow)
def open_page_info_window(self, trigger='menu'): """Opens the page info window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :returns: :class:`PageInfoWindow` instance of the opened window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': self.menubar.select_by_id('tools-menu', 'menu_pageInfo') elif trigger == 'shortcut': if win.marionette.session_capabilities[ 'platformName'] == 'windows': raise ValueError( 'Page info shortcut not available on Windows.') win.send_shortcut( win.localize_entity('pageInfoCmd.commandkey'), accel=True) elif trigger == 'context_menu': # TODO: Add once we can do right clicks pass else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, PageInfoWindow)
def close(self, trigger='menu', force=False): """Closes the current browser window by using the specified trigger. :param trigger: Optional, method to close the current browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :param force: Optional, forces the closing of the window by using the Gecko API. Defaults to `False`. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': self.menubar.select_by_id('file-menu', 'menu_closeWindow') elif trigger == 'shortcut': win.send_shortcut('w', accel=True, shift=True) else: raise ValueError('Unknown closing method: "%s"' % trigger) BaseWindow.close(self, callback, force)
def close(self, trigger='menu', force=False): """Closes the current browser window by using the specified trigger. :param trigger: Optional, method to close the current browser window. This can be a string with one of `menu` or `shortcut`, or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :param force: Optional, forces the closing of the window by using the Gecko API. Defaults to `False`. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': self.menubar.select_by_id('file-menu', 'menu_closeWindow') elif trigger == 'shortcut': win.send_shortcut(win.get_entity('closeCmd.key'), accel=True, shift=True) else: raise ValueError('Unknown closing method: "%s"' % trigger) BaseWindow.close(self, callback, force)
def test_basics(self): # force BaseWindow instance win1 = BaseWindow(self.marionette, self.browser.handle) self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle) self.assertEquals(win1.window_element, self.marionette.find_element(By.CSS_SELECTOR, ':root')) self.assertEquals(win1.window_element.get_attribute('windowtype'), self.marionette.get_window_type()) self.assertFalse(win1.closed) # Test invalid parameters for BaseWindow constructor self.assertRaises(errors.UnknownWindowError, BaseWindow, self.marionette, 10) # Test invalid shortcuts self.assertRaises(KeyError, win1.send_shortcut, 'l', acel=True)
def open_about_window(self, trigger='menu'): """Opens the about window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can either the string `menu` or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :returns: :class:`AboutWindow` instance of the opened window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': self.menubar.select_by_id('helpMenu', 'aboutName') else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, AboutWindow)
def open_about_window(self, trigger='menu'): """Opens the about window by using the specified trigger. :param trigger: Optional, method in how to open the new browser window. This can either the string `menu` or a callback which gets triggered with the current :class:`BrowserWindow` as parameter. Defaults to `menu`. :returns: :class:`AboutWindow` instance of the opened window. """ def callback(win): # Prepare action which triggers the opening of the browser window if callable(trigger): trigger(win) elif trigger == 'menu': # TODO: Make use of menubar class once it supports ids menu = win.marionette.find_element(By.ID, 'aboutName') menu.click() else: raise ValueError('Unknown opening method: "%s"' % trigger) return BaseWindow.open_window(self, callback, AboutWindow)
def test_switch_to_and_focus(self): # force BaseWindow instance win1 = BaseWindow(lambda: self.marionette, self.browser.handle) # Open a new window (will be focused), and check states win2 = win1.open_window() # force BaseWindow instance win2 = BaseWindow(lambda: self.marionette, win2.handle) self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) self.assertEquals(win2.handle, self.windows.focused_chrome_window_handle) self.assertFalse(win1.focused) self.assertTrue(win2.focused) # Switch back to win1 without moving the focus, but focus separately win1.switch_to() self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle) self.assertTrue(win2.focused) win1.focus() self.assertTrue(win1.focused) # Switch back to win2 by focusing it directly win2.focus() self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) self.assertEquals(win2.handle, self.windows.focused_chrome_window_handle) self.assertTrue(win2.focused) # Close win2, and check that it keeps active but looses focus win2.switch_to() win2.close() win1.switch_to()
def test_open_close(self): # force BaseWindow instance win1 = BaseWindow(lambda: self.marionette, self.browser.handle) # Open a new window (will be focused), and check states win2 = win1.open_window() # force BaseWindow instance win2 = BaseWindow(lambda: self.marionette, win2.handle) self.assertEquals(len(self.marionette.chrome_window_handles), 2) self.assertNotEquals(win1.handle, win2.handle) self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) win2.close() self.assertTrue(win2.closed) self.assertEquals(len(self.marionette.chrome_window_handles), 1) self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) Wait(self.marionette).until(lambda _: win1.focused) # catch the no focused window win1.focus() # Open and close a new window by a custom callback def opener(window): window.marionette.execute_script(""" window.open(); """) def closer(window): window.marionette.execute_script(""" window.close(); """) win2 = win1.open_window(callback=opener) # force BaseWindow instance win2 = BaseWindow(lambda: self.marionette, win2.handle) self.assertEquals(len(self.marionette.chrome_window_handles), 2) win2.close(callback=closer) win1.focus() # Check for an unexpected window class self.assertRaises(errors.UnexpectedWindowTypeError, win1.open_window, expected_window_class=BaseWindow) self.windows.close_all([win1])
def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): BaseWindow.__init__(self, *args, **kwargs) self._software_update = SoftwareUpdate(lambda: self.marionette) self._download_duration = None
def test_open_close(self): # force BaseWindow instance win1 = BaseWindow(self.marionette, self.browser.handle) # Open a new window (will be focused), and check states win2 = win1.open_window() # force BaseWindow instance win2 = BaseWindow(self.marionette, win2.handle) self.assertEquals(len(self.marionette.chrome_window_handles), 2) self.assertNotEquals(win1.handle, win2.handle) self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) win2.close() self.assertTrue(win2.closed) self.assertEquals(len(self.marionette.chrome_window_handles), 1) with self.assertRaises(NoSuchWindowException): self.marionette.current_chrome_window_handle Wait(self.marionette).until(lambda _: win1.focused) # catch the no focused window win1.focus() # Open and close a new window by a custom callback def opener(window): window.marionette.execute_script(""" window.open(); """) def closer(window): window.marionette.execute_script(""" window.close(); """) win2 = win1.open_window(callback=opener) # force BaseWindow instance win2 = BaseWindow(self.marionette, win2.handle) self.assertEquals(len(self.marionette.chrome_window_handles), 2) win2.close(callback=closer) win1.focus() # Check for an unexpected window class self.assertRaises(errors.UnexpectedWindowTypeError, win1.open_window, expected_window_class=BaseWindow) self.puppeteer.windows.close_all([win1])
def test_switch_to_and_focus(self): # force BaseWindow instance win1 = BaseWindow(self.marionette, self.browser.handle) # Open a new window (will be focused), and check states win2 = win1.open_window() # force BaseWindow instance win2 = BaseWindow(self.marionette, win2.handle) self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) self.assertEquals(win2.handle, self.puppeteer.windows.focused_chrome_window_handle) self.assertFalse(win1.focused) self.assertTrue(win2.focused) # Switch back to win1 without moving the focus, but focus separately win1.switch_to() self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle) self.assertTrue(win2.focused) win1.focus() self.assertTrue(win1.focused) # Switch back to win2 by focusing it directly win2.focus() self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) self.assertEquals(win2.handle, self.puppeteer.windows.focused_chrome_window_handle) self.assertTrue(win2.focused) # Close win2, and check that it keeps active but looses focus win2.switch_to() win2.close() win1.switch_to()