lib/appium_lib/ios/common/helper.rb in appium_lib-15.0.0 vs lib/appium_lib/ios/common/helper.rb in appium_lib-15.2.0

- old
+ new

@@ -105,11 +105,11 @@ # Get the element of type class_name at matching index. # @param class_name [String] the class name to find # @param index [Integer] the index # @return [Element] def ele_index(class_name, index) - raise 'Index must be >= 1' unless index == 'last()' || (index.is_a?(Integer) && index >= 1) + raise ArgumentError, 'Index must be >= 1' unless index == 'last()' || (index.is_a?(Integer) && index >= 1) elements = tags(class_name) if index == 'last()' result = elements.last @@ -374,11 +374,11 @@ # # visible - if true, only visible elements are returned. default true # def _all_pred(opts) predicate = opts[:predicate] - raise 'predicate must be provided' unless predicate + raise ArgumentError, 'predicate must be provided' unless predicate visible = opts.fetch :visible, true %($.mainApp().getAllWithPredicate("#{predicate}", #{visible});) end @@ -402,27 +402,27 @@ def eles_with_pred(opts) find_elements(:uiautomation, _all_pred(opts)) end def _validate_object(*objects) - raise 'objects must be an array' unless objects.is_a? Array + raise ArgumentError, 'objects must be an array' unless objects.is_a? Array objects.each do |obj| next unless obj # obj may be nil. if so, ignore. valid_keys = %i[target substring insensitive] unknown_keys = obj.keys - valid_keys - raise "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? + raise ArgumentError, "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? target = obj[:target] - raise 'target must be a string' unless target.is_a? String + raise ArgumentError, 'target must be a string' unless target.is_a? String substring = obj[:substring] - raise 'substring must be a boolean' unless [true, false].include? substring + raise ArgumentError, 'substring must be a boolean' unless [true, false].include? substring insensitive = obj[:insensitive] - raise 'insensitive must be a boolean' unless [true, false].include? insensitive + raise ArgumentError, 'insensitive must be a boolean' unless [true, false].include? insensitive end end # For Appium(automation name), not XCUITest # typeArray - array of string types to search for. Example: ["UIAStaticText"] @@ -454,19 +454,19 @@ # } # def _by_json(opts) valid_keys = %i(typeArray onlyFirst onlyVisible name label value) unknown_keys = opts.keys - valid_keys - raise "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? + raise ArgumentError, "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? type_array = opts[:typeArray] - raise 'typeArray must be an array' unless type_array.is_a? Array + raise ArgumentError, 'typeArray must be an array' unless type_array.is_a? Array only_first = opts[:onlyFirst] - raise 'onlyFirst must be a boolean' unless [true, false].include? only_first + raise ArgumentError, 'onlyFirst must be a boolean' unless [true, false].include? only_first only_visible = opts[:onlyVisible] - raise 'onlyVisible must be a boolean' unless [true, false].include? only_visible + raise ArgumentError, 'onlyVisible must be a boolean' unless [true, false].include? only_visible # name/label/value are optional. when searching for class only, then none # will be present. _validate_object opts[:name], opts[:label], opts[:value]