Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#513] FIX: Fix error message thrown by selenium exceptions upon wait #512

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading