本文整理汇总了Python中firefox_puppeteer.ui.windows.BaseWindow.close方法的典型用法代码示例。如果您正苦于以下问题:Python BaseWindow.close方法的具体用法?Python BaseWindow.close怎么用?Python BaseWindow.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类firefox_puppeteer.ui.windows.BaseWindow
的用法示例。
在下文中一共展示了BaseWindow.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_switch_to_and_focus
# 需要导入模块: from firefox_puppeteer.ui.windows import BaseWindow [as 别名]
# 或者: from firefox_puppeteer.ui.windows.BaseWindow import close [as 别名]
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()
示例2: test_open_close
# 需要导入模块: from firefox_puppeteer.ui.windows import BaseWindow [as 别名]
# 或者: from firefox_puppeteer.ui.windows.BaseWindow import close [as 别名]
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])
示例3: close
# 需要导入模块: from firefox_puppeteer.ui.windows import BaseWindow [as 别名]
# 或者: from firefox_puppeteer.ui.windows.BaseWindow import close [as 别名]
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)