Created
May 3, 2022 18:20
-
-
Save Snarp/899253f4f48e0a97f66cf29ff709d6f5 to your computer and use it in GitHub Desktop.
Automatically build a list of all Selenium / Watir webdriver errors and rescue all of them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'watir' | |
require 'selenium-webdriver' | |
require 'logger' | |
# Selenium::WebDriver::Error.constants | |
# => [:WebDriverError, :NoSuchElementError, :NoSuchFrameError, ...] | |
def rescue_every_single_goddamn_webdriver_error | |
selenium_errors = Selenium::WebDriver::Error.constants.map do |e_symbol| | |
Selenium::WebDriver::Error.const_get(e_symbol) | |
end.select { |e_class| e_class.is_a?(Class) && e_class < Exception } | |
watir_errors = child_errors_for(Watir::Exception) | |
all_errors = selenium_errors + watir_errors | |
begin | |
some_element.click | |
rescue *all_errors => e | |
logger.error "#{e.class} #{e.message}" | |
return false | |
else | |
logger.info "No errors found" | |
return true | |
end | |
end | |
def child_errors_for(parent=Selenium::WebDriver::Error) | |
parent.constants.map do |e_symbol| | |
parent.const_get(e_symbol) | |
end.select { |e_class| e_class.is_a?(Class) && e_class < Exception } | |
end | |
def child_classes_for(parent) | |
parent.constants.map do |child_symbol| | |
parent.const_get(child_symbol) | |
end.select { |child_class| child_class.is_a?(Class) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment