Skip to content

Conversation

mxschmitt
Copy link
Member

@mxschmitt mxschmitt commented Jul 11, 2020

This test is missing and failing / hanging (not included in the PR) in the last line with the await. Not sure why it's not passing. From my understanding the RPC server does not return the request body anymore in this case (saw it in the protocol).

async def test_response_text_should_wait_until_responses_completes(page, server):
    await page.goto(server.EMPTY_PAGE)
    ## Setup server to trap request.
    server_response_future = asyncio.Future()

    def handle_request(request):
        # In Firefox, |fetch| will be hanging until it receives |Content-Type| header
        # from server.
        request.setHeader("Content-Type", "text/plain charset=utf-8")
        request.write(b"hello ")
        server_response_future.set_result(request)

    server.set_route("/get", handle_request)
    # Setup page to trap response.
    request_finished = False

    def handle_request_finished(request):
        global request_finished
        request_finished = request_finished or "/get" in request.url

    page.on("requestfinished", handle_request_finished)
    # send request and wait for server response
    page_response = (
        await asyncio.gather(
            page.waitForEvent("response"),
            page.evaluate("() => fetch('./get', { method: 'GET'})"),
            server.wait_for_request("/get"),
        )
    )[0]
    server_response = await server_response_future
    assert server_response
    assert page_response
    assert page_response.status == 200
    assert request_finished is False

    response_text = asyncio.ensure_future(page_response.text())
    # Write part of the response and wait for it to be flushed.
    server_response.write(b"wor")
    # Finish response.
    server_response.write(b"ld!")
    server_response.finish()
    assert await response_text == "hello world!"

@mxschmitt mxschmitt force-pushed the tests/network branch 2 times, most recently from a901d57 to a3c0e82 Compare July 11, 2020 22:45
@pavelfeldman
Copy link
Member

If I modify your script to store the fetch result (promise to response) in property fooo and then append the following to after you do server_response.finish():

    print(await page.evaluate('''async () => {
        const response = await window.fooo;
        return response.text();
    }'''))

It never resolves. This suggests that the server does something wrong - it does not work without any Playwright logic...

@mxschmitt
Copy link
Member Author

   print(await page.evaluate('''async () => {
        const response = await window.fooo;
        return response.text();
    }'''))

Yep, I was also trying to check if the server is working as expected. But the Chrome DevTools are reporting it correctly.

Screenshot 2020-07-12 at 10 54 14

Screenshot 2020-07-12 at 10 54 05

@pavelfeldman
Copy link
Member

devtools show you request and response (headers), i bet that the preview is empty though, because body was not retrieved.

@pavelfeldman pavelfeldman merged commit afcf39e into microsoft:master Jul 12, 2020
@mxschmitt mxschmitt mentioned this pull request Jul 12, 2020
34 tasks
@mxschmitt mxschmitt deleted the tests/network branch July 14, 2020 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants