Skip to content

Commit

Permalink
[py] handle w3c key case for stacktrace
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Tierney <[email protected]>
  • Loading branch information
lmtierney committed Jun 20, 2019
1 parent 2748e5d commit b8af26b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions py/selenium/webdriver/remote/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,13 @@ def check_response(self, response):
screen = value['screen']

stacktrace = None
if 'stackTrace' in value and value['stackTrace']:
st_value = value.get('stackTrace') or value.get('stacktrace')
if st_value:
if isinstance(st_value, basestring):
st_value = st_value.split('\n')
stacktrace = []
try:
for frame in value['stackTrace']:
for frame in st_value:
line = self._value_or_default(frame, 'lineNumber', '')
file = self._value_or_default(frame, 'fileName', '<anonymous>')
if line:
Expand Down
14 changes: 14 additions & 0 deletions py/test/unit/selenium/webdriver/remote/test_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,17 @@ def test_raises_exception_for_unknown_method(handler, code):
def test_raises_exception_for_method_not_allowed(handler, code):
with pytest.raises(exceptions.WebDriverException):
handler.check_response({'status': code, 'value': 'foo'})


@pytest.mark.parametrize('key', ['stackTrace', 'stacktrace'])
def test_relays_exception_stacktrace(handler, key):
import json
stacktrace = {'lineNumber': 100, 'fileName': 'egg', 'methodName': 'ham', 'className': 'Spam'}
value = {key: [stacktrace],
'message': 'very bad',
'error': ErrorCode.UNKNOWN_METHOD[0]}
response = {'status': 400, 'value': json.dumps({'value': value})}
with pytest.raises(exceptions.UnknownMethodException) as e:
handler.check_response(response)

assert 'Spam.ham' in e.value.stacktrace[0]

0 comments on commit b8af26b

Please sign in to comment.