コード例 #1
0
def test_context_managers(browser_type: BrowserType, launch_arguments):
    with browser_type.launch(**launch_arguments) as browser:
        with browser.new_context() as context:
            with context.new_page():
                assert len(context.pages) == 1
            assert len(context.pages) == 0
            assert len(browser.contexts) == 1
        assert len(browser.contexts) == 0
    assert not browser.is_connected()
コード例 #2
0
def test_connect_to_an_existing_cdp_session(launch_arguments: Dict,
                                            browser_type: BrowserType) -> None:
    port = find_free_port()
    browser_server = browser_type.launch(**launch_arguments,
                                         args=[
                                             f"--remote-debugging-port={port}"
                                         ])
    cdp_browser = browser_type.connect_over_cdp(f"http://localhost:{port}")
    assert len(cdp_browser.contexts) == 1
    cdp_browser.close()
    browser_server.close()
コード例 #3
0
def browser(
    browser_type: BrowserType, launch_arguments: Dict
) -> Generator[Browser, None, None]:
    browser = browser_type.launch(**launch_arguments)
    yield browser
    browser.close()
コード例 #4
0
def _browser(
        browser_type: BrowserType,
        browser_type_launch_args: dict) -> t.Generator[Browser, None, None]:
    browser = browser_type.launch(**browser_type_launch_args)
    yield browser
    browser.close()