@@ -546,6 +546,16 @@ async def _coro(value):
546546 return value
547547
548548
549+ def _response_cookie_present (recording , path_suffix , name ):
550+ entry = _origin_entry (recording , path_suffix )
551+ return entry is not None and any (c ['name' ] == name for c in entry ['response' ]['cookies' ])
552+
553+
554+ def _request_cookie_present (recording , path_suffix , name ):
555+ entry = _origin_entry (recording , path_suffix )
556+ return entry is not None and any (c ['name' ] == name for c in entry ['request' ]['cookies' ])
557+
558+
549559class _RequestSentWaiter :
550560 """Arm a listener for a ``Network.requestWillBeSent`` event before navigating.
551561
@@ -634,6 +644,14 @@ async def test_record_captures_response_cookies(self, ci_chrome_options, api_ser
634644 await tab .go_to (f'{ api_server } /cookies-page' )
635645 assert await _wait_for_requests_done (tab ), 'Page requests did not complete'
636646 await _wait_for_network_idle (tab )
647+ # Set-Cookie arrives via the async responseReceivedExtraInfo event,
648+ # which can land after load; poll the live recording until it folds in.
649+ await wait_until (
650+ lambda : _coro (
651+ _response_cookie_present (recording , '/set-cookie' , 'har_session' )
652+ ),
653+ message = 'Set-Cookie not captured into HAR within timeout' ,
654+ )
637655
638656 set_cookie_entry = _origin_entry (recording , '/set-cookie' )
639657 assert set_cookie_entry is not None
@@ -662,6 +680,12 @@ async def test_record_captures_request_cookies(self, ci_chrome_options, api_serv
662680 await tab .go_to (f'{ api_server } /cookies-page' )
663681 assert await _wait_for_requests_done (tab ), 'Page requests did not complete'
664682 await _wait_for_network_idle (tab )
683+ await wait_until (
684+ lambda : _coro (
685+ _request_cookie_present (recording , '/needs-cookie' , 'har_session' )
686+ ),
687+ message = 'request Cookie not captured into HAR within timeout' ,
688+ )
665689
666690 needs_cookie_entry = _origin_entry (recording , '/needs-cookie' )
667691 assert needs_cookie_entry is not None
0 commit comments