Skip to content

Commit

Permalink
FIX: Fix error message thrown by selenium exceptions upon wait
Browse files Browse the repository at this point in the history
Currently we were casting entire exception to the string (including not readable stacktrace) from selenium to error message. Instead, we should pass just the error message
  • Loading branch information
jacekziembla authored and jacekz committed Feb 10, 2024
1 parent 1dd26e2 commit d638fcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 1 addition & 3 deletions selene/core/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ def logic(fn: Callable[[E], R]) -> R:
return fn(self.entity)
except Exception as reason:
if time.time() > finish_time:
reason_message = str(reason)

reason_string = '{name}: {message}'.format(
name=reason.__class__.__name__,
message=reason_message,
message=getattr(reason, "msg", str(reason)),
)
# TODO: think on how can we improve logging failures in selene, e.g. reverse msg and stacktrace
# stacktrace = getattr(reason, 'stacktrace', None)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/element__type_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_type_failure_when_invisible(session_browser):
assert time_spent >= 1
browser.element('#text-field').should(have.value('before'))
assert (
'Reason: JavascriptException: Message: javascript error: '
'Reason: JavascriptException: javascript error: '
'element '
'<input id="text-field" value="before" style="display: none"> '
'is not visible\n'
Expand Down
20 changes: 12 additions & 8 deletions tests/integration/error_messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ def test_element_search_fails_with_message_when_implicitly_waits_for_condition(
'Timed out after 0.1s, while waiting for:',
"browser.element(('css selector', '#hidden-button')).click",
'',
'Reason: ElementNotInteractableException: Message: element not interactable',
'Reason: ElementNotInteractableException: element not interactable',
'(Session info: *)',
'Stacktrace: *',
'Screenshot: *.png',
'PageSource: *.html',
]


Expand All @@ -119,9 +120,10 @@ def test_inner_element_search_fails_with_message_when_implicitly_waits_for_condi
"browser.element(('css selector', '#container')).element(('css selector', "
"'#hidden-button')).click",
'',
'Reason: ElementNotInteractableException: Message: element not interactable',
'Reason: ElementNotInteractableException: element not interactable',
'(Session info: *)',
'Stacktrace: *',
'Screenshot: *.png',
'PageSource: *.html',
]


Expand All @@ -146,9 +148,10 @@ def test_inner_element_search_fails_with_message_when_implicitly_waits_for_condi
"browser.element(('css selector', '#hidden-container')).element(('css "
"selector', '#button')).click",
'',
'Reason: ElementNotInteractableException: Message: element not interactable',
'Reason: ElementNotInteractableException: element not interactable',
'(Session info: *)',
'Stacktrace: *',
'Screenshot: *.png',
'PageSource: *.html',
]


Expand All @@ -173,11 +176,12 @@ def test_inner_element_search_fails_with_message_when_implicitly_waits_for_condi
"browser.element(('css selector', '#not-existing')).element(('css selector', "
"'#button')).click",
'',
'Reason: NoSuchElementException: Message: no such element: Unable to locate '
'Reason: NoSuchElementException: no such element: Unable to locate '
'element: {"method":"css selector","selector":"#not-existing"}',
'(Session info: *); For documentation on this error, please visit: '
'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception',
'Stacktrace: *',
'Screenshot: *.png',
'PageSource: *.html',
]


Expand Down

0 comments on commit d638fcf

Please sign in to comment.