Skip to content

Commit

Permalink
Merge pull request #512 from jacekziembla/patch-1
Browse files Browse the repository at this point in the history
[#513] FIX: Fix error message thrown by selenium exceptions upon wait
  • Loading branch information
yashaka authored Feb 12, 2024
2 parents 1dd26e2 + 73f2d00 commit e3bfdbb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 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/browser__actions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_browser_actions_fails_to_wait_for_drag_and_drop_before_perform(
assert (
"browser.element(('css selector', '#draggable')).locate webelement\n"
"\n"
"Reason: NoSuchElementException: Message: "
"Reason: NoSuchElementException: "
"no such element: Unable to locate element: "
"{\"method\":\"css selector\",\"selector\":\"#draggable\"}\n"
) in str(error)
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 e3bfdbb

Please sign in to comment.