本文整理汇总了Python中marionette.Marionette.switch_to_window方法的典型用法代码示例。如果您正苦于以下问题:Python Marionette.switch_to_window方法的具体用法?Python Marionette.switch_to_window怎么用?Python Marionette.switch_to_window使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marionette.Marionette
的用法示例。
在下文中一共展示了Marionette.switch_to_window方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConsoleLogCapture
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import switch_to_window [as 别名]
class TestConsoleLogCapture():
def setup(self):
try:
self.client = Marionette(host='localhost', port=2828)
self.client.start_session()
self.client.set_pref('general.warnOnAboutConfig', False)
except:
sys.exit("Could not find Firefox browser running")
def test_push_notification_received(self):
self.client.navigate("https://people.mozilla.org/~ewong2/push-notification-test/")
unregister_button = self.client.find_element(By.ID, "unreg_btn")
if unregister_button.is_displayed() == True:
unregister_button.click()
Wait(self.client, timeout=5, interval=1).until(expected.element_not_displayed(By.ID, "unreg_btn"))
Wait(self.client).until(expected.element_displayed(By.ID, "reg_btn"))
self.client.find_element(By.ID, "reg_btn").click()
Wait(self.client).until(expected.element_displayed(By.ID, "subscribe_btn"))
self.client.find_element(By.ID, "subscribe_btn").click()
Wait(self.client).until(expected.element_displayed(By.ID, "doXhr_btn"))
self.client.find_element(By.ID, "doXhr_btn").click()
result = self.web_console_filter_for_string("Received a push message")
assert result == 1
def web_console_filter_for_string(self, console_string=None):
self.client.set_context(self.client.CONTEXT_CHROME)
handles = self.client.window_handles
chrome_handles = self.client.chrome_window_handles
browser_handle = self.client.current_chrome_window_handle
notifications = 0
for handle in chrome_handles:
if handle != browser_handle:
console_handle = handle
self.client.switch_to_window(console_handle)
time.sleep(1)
results = self.client.find_elements(By.CLASS_NAME, "console-string")
for result in results:
if console_string in result.text:
notifications = notifications + 1
self.client.find_element(By.CLASS_NAME, "webconsole-clear-console-button").click()
return notifications
def tear_down(self):
self.client.close()
示例2: TestServer
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import switch_to_window [as 别名]
# start the test server
server = TestServer(2626)
thread = threading.Thread(target=server.run)
thread.daemon = True
thread.start()
# run some trivial unit tests which just verify the protocol
m = Marionette(host='localhost', port=2626)
assert(m.status()['os']['arch'] == 'x86')
assert(m.start_session())
assert(m.get_session_capabilities()['javascriptEnabled'] == True)
assert(m.get_window() == server.TEST_CURRENT_WINDOW)
assert(m.window == server.TEST_CURRENT_WINDOW)
assert(m.get_windows() == server.TEST_WINDOW_LIST)
assert(m.switch_to_window('window2'))
assert(m.window == 'window2')
assert(m.close_window('window2'))
assert(m.set_script_timeout(1000))
assert(m.set_search_timeout(500))
assert(m.get_url() == server.TEST_URL)
assert(m.navigate(server.TEST_URL))
assert(m.go_back())
assert(m.go_forward())
assert(m.refresh())
assert(m.execute_script(server.TEST_EXECUTE_SCRIPT))
assert(m.execute_js_script(server.TEST_EXECUTE_SCRIPT))
assert(m.execute_js_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))
assert(m.execute_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))
assert(m.execute_async_script(server.TEST_EXECUTE_SCRIPT))
assert(m.execute_async_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))