diff options
Diffstat (limited to 'crocoite/test_devtools.py')
-rw-r--r-- | crocoite/test_devtools.py | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/crocoite/test_devtools.py b/crocoite/test_devtools.py index 74d223f..bd1a828 100644 --- a/crocoite/test_devtools.py +++ b/crocoite/test_devtools.py @@ -24,7 +24,8 @@ import pytest from aiohttp import web import websockets -from .devtools import Browser, Tab, MethodNotFound, Crashed, InvalidParameter, Process, Passthrough +from .devtools import Browser, Tab, MethodNotFound, Crashed, \ + InvalidParameter, Process, Passthrough @pytest.fixture async def browser (): @@ -38,8 +39,9 @@ async def tab (browser): # make sure there are no transactions left over (i.e. no unawaited requests) assert not tab.transactions +docBody = "<html><body><p>Hello, world</p></body></html>" async def hello(request): - return web.Response(text="Hello, world") + return web.Response(text=docBody, content_type='text/html') @pytest.fixture async def server (): @@ -73,8 +75,10 @@ async def test_tab_close (browser): @pytest.mark.asyncio async def test_tab_notify_enable_disable (tab): - """ Make sure enabling/disabling notifications works for all known namespaces """ - for name in ('Debugger', 'DOM', 'Log', 'Network', 'Page', 'Performance', 'Profiler', 'Runtime', 'Security'): + """ Make sure enabling/disabling notifications works for all known + namespaces """ + for name in ('Debugger', 'DOM', 'Log', 'Network', 'Page', 'Performance', + 'Profiler', 'Runtime', 'Security'): f = getattr (tab, name) await f.enable () await f.disable () @@ -109,14 +113,45 @@ async def test_tab_crash (tab): async def test_load (tab, server): await tab.Network.enable () await tab.Page.navigate (url='http://localhost:8080') - method, req = await tab.get () - assert method == tab.Network.requestWillBeSent - method, resp = await tab.get () - assert method == tab.Network.responseReceived - assert tab.pending == 0 - body = await tab.Network.getResponseBody (requestId=req['requestId']) - assert body['body'] == "Hello, world" + + haveRequest = False + haveResponse = False + haveData = False + haveFinished = False + haveBody = False + req = None + resp = None + while not haveBody: + method, data = await tab.get () + + # it can be either of those two in no specified order + if method in (tab.Network.requestWillBeSent, tab.Network.requestWillBeSentExtraInfo) and not haveResponse: + if req is None: + req = data + assert data['requestId'] == req['requestId'] + haveRequest = True + elif method in (tab.Network.responseReceived, tab.Network.responseReceivedExtraInfo) and haveRequest: + if resp is None: + resp = data + assert data['requestId'] == resp['requestId'] + haveResponse = True + elif haveRequest and haveResponse and method == tab.Network.dataReceived: + assert data['dataLength'] == len (docBody) + assert data['requestId'] == req['requestId'] + haveData = True + elif haveData: + assert method == tab.Network.loadingFinished + assert data['requestId'] == req['requestId'] + haveBody = True + elif haveFinished: + body = await tab.Network.getResponseBody (requestId=req['requestId']) + assert body['body'] == docBody + haveBody = True + else: + assert False, (method, req) + await tab.Network.disable () + assert tab.pending == 0 @pytest.mark.asyncio async def test_recv_failure(browser): @@ -149,7 +184,8 @@ async def test_tab_function (tab): @pytest.mark.asyncio async def test_tab_function_hash (tab): - d = {tab.Network.enable: 1, tab.Network.disable: 2, tab.Page: 3, tab.Page.enable: 4} + d = {tab.Network.enable: 1, tab.Network.disable: 2, tab.Page: 3, + tab.Page.enable: 4} assert len (d) == 4 @pytest.mark.asyncio @@ -168,5 +204,5 @@ async def test_passthrough (): url = 'http://localhost:12345' async with Passthrough (url) as u: - assert u == url + assert str (u) == url |