当前位置: 首页>>代码示例>>Python>>正文


Python Marionette.switch_to_window方法代码示例

本文整理汇总了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()
开发者ID:stuartphilp,项目名称:marionnette_webconsole,代码行数:51,代码来源:marionnette_webconsole_example.py

示例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))
开发者ID:Kml55,项目名称:marionette_client,代码行数:32,代码来源:test_protocol.py


注:本文中的marionette.Marionette.switch_to_window方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。