Commit 12aa7172 authored by Tricia Crichton's avatar Tricia Crichton Committed by Commit Bot

[ChromeDriver] Extract sessionId from W3C response

In W3C mode for ChromeDriver, the response format changed. Code
was modified to extract sessionId from the new response format.

Bug: chromedriver:3076
Change-Id: Iaf749fa480fcbe541d8b520357c4344c79241dc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1746787Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Tricia Crichton <triciac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686452}
parent 2a9a5b78
...@@ -748,8 +748,13 @@ class CommandSequence(object): ...@@ -748,8 +748,13 @@ class CommandSequence(object):
self._id_map[id_old] = id_new self._id_map[id_old] = id_new
self._staged_logged_ids = None self._staged_logged_ids = None
if "sessionId" in response and self._staged_logged_session_id: # In W3C format, the http response is a single key dict,
self._id_map[self._staged_logged_session_id] = response["sessionId"] # where the value is another dictionary
# sessionId is contained in the nested dictionary
if ("value" in response and "sessionId" in response["value"]
and self._staged_logged_session_id):
self._id_map[self._staged_logged_session_id] = (
response["value"]["sessionId"])
self._staged_logged_session_id = None self._staged_logged_session_id = None
def _IngestLoggedResponse(self, response): def _IngestLoggedResponse(self, response):
......
...@@ -116,6 +116,23 @@ class ChromeDriverClientReplayUnitTest(unittest.TestCase): ...@@ -116,6 +116,23 @@ class ChromeDriverClientReplayUnitTest(unittest.TestCase):
self.assertEqual(response.GetPayloadPrimitive(), {"param2": 42}) self.assertEqual(response.GetPayloadPrimitive(), {"param2": 42})
self.assertEqual(response.session_id, _SESSION_ID) self.assertEqual(response.session_id, _SESSION_ID)
def testIngestRealResponseInitSession(self):
real_resp = {u'value': {
u'sessionId': u'b15232d5497ec0d8300a5a1ea56f33ce',
u'capabilities': {
u'browserVersion': u'76.0.3809.100',
u'browserName': u'chrome',
}
}}
command_sequence = client_replay.CommandSequence()
command_sequence._staged_logged_session_id = _SESSION_ID_ALT
command_sequence._IngestRealResponse(real_resp)
self.assertEqual(
command_sequence._id_map[_SESSION_ID_ALT], _SESSION_ID)
self.assertEqual(command_sequence._staged_logged_session_id, None)
def testGetPayload_simple(self): def testGetPayload_simple(self):
string_buffer = StringIO.StringIO(_RESPONSE_ONLY) string_buffer = StringIO.StringIO(_RESPONSE_ONLY)
header = string_buffer.readline() header = string_buffer.readline()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment