コード例 #1
0
async def test_connect_to_an_existing_cdp_session_twice(
    launch_arguments: Dict, browser_type: BrowserType, server: Server
):
    port = find_free_port()
    browser_server = await browser_type.launch(
        **launch_arguments, args=[f"--remote-debugging-port={port}"]
    )
    wait_for_port(port)
    endpoint_url = f"http://localhost:{port}"
    cdp_browser1 = await browser_type.connect_over_cdp(endpoint_url)
    cdp_browser2 = await browser_type.connect_over_cdp(endpoint_url)
    assert len(cdp_browser1.contexts) == 1
    page1 = await cdp_browser1.contexts[0].new_page()
    await page1.goto(server.EMPTY_PAGE)

    assert len(cdp_browser2.contexts) == 1
    page2 = await cdp_browser2.contexts[0].new_page()
    await page2.goto(server.EMPTY_PAGE)

    assert len(cdp_browser1.contexts[0].pages) == 2
    assert len(cdp_browser2.contexts[0].pages) == 2

    await cdp_browser1.close()
    await cdp_browser2.close()
    await browser_server.close()
コード例 #2
0
async def test_connect_to_an_existing_cdp_session(launch_arguments: Dict,
                                                  browser_type: BrowserType):
    port = find_free_port()
    browser_server = await browser_type.launch(
        **launch_arguments, args=[f"--remote-debugging-port={port}"])
    cdp_browser = await browser_type.connect_over_cdp(
        f"http://localhost:{port}")
    assert len(cdp_browser.contexts) == 1
    await cdp_browser.close()
    await browser_server.close()
コード例 #3
0
async def test_conect_over_a_ws_endpoint(launch_arguments: Dict,
                                         browser_type: BrowserType,
                                         server: Server):
    port = find_free_port()
    browser_server = await browser_type.launch(
        **launch_arguments, args=[f"--remote-debugging-port={port}"])
    ws_endpoint = _ws_endpoint_from_url(
        f"http://localhost:{port}/json/version/")

    cdp_browser1 = await browser_type.connect_over_cdp(ws_endpoint)
    assert len(cdp_browser1.contexts) == 1
    await cdp_browser1.close()

    cdp_browser2 = await browser_type.connect_over_cdp(ws_endpoint)
    assert len(cdp_browser2.contexts) == 1
    await cdp_browser2.close()
    await browser_server.close()