yashaka / selene

User-oriented Web UI browser tests in Python
https://yashaka.github.io/selene/
MIT License
676 stars 145 forks source link

Change error message thrown by Waiter methods to exclude selenium stacktrace from message #513

Closed jacekziembla closed 4 months ago

jacekziembla commented 4 months ago

Currently, we were casting entire exception object (as results it contains the error message and error stacktrace) to the string that originates from selenium to error message. Instead, we could pass just the error message, to make the output more readable.

Current:

.venv/lib/python3.8/site-packages/selene/core/wait.py:143: in for_
     return self._decorator(self)(logic)(fn)
 .venv/lib/python3.8/site-packages/selene/core/wait.py:141: in logic
     raise self._hook_failure(failure)
 E   selene.core.exceptions.TimeoutException: Message: 
 E   
 E   Timed out after 1s, while waiting for:
 E   browser.element(('id', 'UserName')).is present in DOM
 E   
 E   Reason: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="UserName"]"}
 E     (Session info: chrome=121.0.6167.160); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
 E   Stacktrace:
 E   0   chromedriver                        0x00000001009c0168 chromedriver + 4673896
 E   1   chromedriver                        0x00000001009b79c3 chromedriver + 4639171
 E   2   chromedriver                        0x00000001005abfdd chromedriver + 397277
 E   3   chromedriver                        0x00000001005f7bfc chromedriver + 707580
 E   4   chromedriver                        0x00000001005f7dd1 chromedriver + 708049
 E   5   chromedriver                        0x000000010063c284 chromedriver + 987780
 E   6   chromedriver                        0x000000010061a8ed chromedriver + 850157
 E   7   chromedriver                        0x0000000100639796 chromedriver + 976790
 E   8   chromedriver                        0x000000010061a663 chromedriver + 849507
 E   9   chromedriver                        0x00000001005ea1cf chromedriver + 651727
 E   10  chromedriver                        0x00000001005eb1ae chromedriver + 655790
 E   11  chromedriver                        0x0000000100980380 chromedriver + 4412288
 E   12  chromedriver                        0x0000000100985798 chromedriver + 4433816
 E   13  chromedriver                        0x0000000100964d71 chromedriver + 4300145
 E   14  chromedriver                        0x00000001009864e6 chromedriver + 4437222
 E   15  chromedriver                        0x0000000100956d3c chromedriver + 4242748
 E   16  chromedriver                        0x00000001009a6208 chromedriver + 4567560
 E   17  chromedriver                        0x00000001009a63be chromedriver + 4567998
 E   18  chromedriver                        0x00000001009b7603 chromedriver + 4638211
 E   19  libsystem_pthread.dylib             0x00007ff805e53202 _pthread_start + 99
 E   20  libsystem_pthread.dylib             0x00007ff805e4ebab thread_start + 15

Proposal:

.venv/lib/python3.8/site-packages/selene/core/wait.py:141: in for_
     return self._decorator(self)(logic)(fn)
 .venv/lib/python3.8/site-packages/selene/core/wait.py:139: in logic
     raise self._hook_failure(failure)
 E selene.core.exceptions.TimeoutException: Message: 
 E   
 E Timed out after 1s, while waiting for:
 E browser.element(('id', 'UserName')).is present in DOM
 E   
 E Reason: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[id="UserName"]"}
 E (Session info: chrome=121.0.6167.160); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
yashaka commented 4 months ago

Hm... seems like really a good point! I'll watch on the PR soon, probably till monday evening...