Is there a way to capture errors occurring in the DOM in Selenium and probably flag the same as an error in the page?
To give a brief exam
I use the following TestCase.tearDown() in my Python Selenium tests that makes the test fail in case of JavaScript errors:
def tearDown(self):
browser_logs = driver.get_log("browser")
errors = [logentry['message'] for logentry in browser_logs if logentry['level'] == 'SEVERE']
if errors:
self.fail(f'The following JavaScript errors occurred: {"; ".join(errors)}')
This is inspired by @kleptog and @d3ming answers.