Class: Applitools::Selenium::VgMatchWindowData
- Inherits:
-
MatchWindowData
- Object
- MatchWindowData
- Applitools::Selenium::VgMatchWindowData
- Defined in:
- lib/applitools/selenium/visual_grid/vg_match_window_data.rb
Defined Under Namespace
Classes: RegionCoordinatesError
Constant Summary collapse
- CONVERT_COORDINATES =
proc do |region, selector_regions| begin offset_region = selector_regions.last new_location = region.location.offset_negative(Applitools::Location.new(offset_region['x'].to_i, offset_region['y'].to_i)) region.location = new_location rescue Applitools::EyesLogger.error("Failed to convert coordinates for #{region}") end end
Instance Attribute Summary collapse
-
#selector_regions ⇒ Object
Returns the value of attribute selector_regions.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #convert_accessibility_regions_coordinates ⇒ Object
- #convert_content_regions_coordinates ⇒ Object
- #convert_floating_regions_coordinates ⇒ Object
- #convert_ignored_regions_coordinates ⇒ Object
- #convert_layout_regions_coordinates ⇒ Object
- #convert_strict_regions_coordinates ⇒ Object
- #obtain_regions_coordinates(regions, driver) ⇒ Object
- #read_target(target, driver, selector_regions) ⇒ Object
Instance Attribute Details
#selector_regions ⇒ Object
Returns the value of attribute selector_regions.
22 23 24 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 22 def selector_regions @selector_regions end |
#target ⇒ Object
Returns the value of attribute target.
22 23 24 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 22 def target @target end |
Instance Method Details
#convert_accessibility_regions_coordinates ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 177 def convert_accessibility_regions_coordinates return unless @need_convert_accessibility_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @accessibility_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.accessibility_regions = @accessibility_regions @need_convert_accessibility_regions_coordinates = false end |
#convert_content_regions_coordinates ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 168 def convert_content_regions_coordinates return unless @need_convert_content_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @content_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.content_regions = @content_regions @need_convert_content_regions_coordinates = false end |
#convert_floating_regions_coordinates ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 141 def convert_floating_regions_coordinates return unless @need_convert_floating_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @floating_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.floating_regions = @floating_regions @need_convert_floating_regions_coordinates = false end |
#convert_ignored_regions_coordinates ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 132 def convert_ignored_regions_coordinates return unless @need_convert_ignored_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @ignored_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.ignored_regions = @ignored_regions.map(&:with_padding).map(&:to_hash) @need_convert_ignored_regions_coordinates = false end |
#convert_layout_regions_coordinates ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 150 def convert_layout_regions_coordinates return unless @need_convert_layout_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @layout_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.layout_regions = @layout_regions @need_convert_layout_regions_coordinates = false end |
#convert_strict_regions_coordinates ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 159 def convert_strict_regions_coordinates return unless @need_convert_strict_regions_coordinates if target.convert_coordinates_block.is_a?(Proc) @strict_regions.each { |r| target.convert_coordinates_block.call(r, selector_regions)} end self.strict_regions = @strict_regions @need_convert_strict_regions_coordinates = false end |
#obtain_regions_coordinates(regions, driver) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 106 def obtain_regions_coordinates(regions, driver) result = [] regions.each do |r| case r when Proc region = r.call(driver) region = selector_regions[target.regions[region]] result << Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) when Applitools::Region result << r when Applitools::Selenium::VGRegion region = r.region region = selector_regions[target.regions[region]] raise RegionCoordinatesError.new(r, region['error']) if region['error'] retrieved_region = Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) result_region = if r.padding_proc.is_a? Proc r.padding_proc.call(retrieved_region) else retrieved_region end result << result_region end end result end |
#read_target(target, driver, selector_regions) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/applitools/selenium/visual_grid/vg_match_window_data.rb', line 23 def read_target(target, driver, selector_regions) self.target = target self.selector_regions = selector_regions # options .each do |field| a_value = target.[field.to_sym] send("#{field}=", a_value) unless a_value.nil? end # ignored regions if target.respond_to? :ignored_regions target.ignored_regions.each do |r| @need_convert_ignored_regions_coordinates = true unless @need_convert_ignored_regions_coordinates case r when Proc region, padding_proc = r.call(driver, true) region = selector_regions[target.regions[region]] retrieved_region = Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) @ignored_regions << padding_proc.call(retrieved_region) if padding_proc.is_a? Proc when Applitools::Region @ignored_regions << r when Applitools::Selenium::VGRegion region = target.regions.key?(r.region) ? selector_regions[target.regions[r.region]] : r.region raise RegionCoordinatesError.new(r, region['error']) if region['error'] retrieved_region = Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) @ignored_regions << if r.padding_proc.is_a?(Proc) r.padding_proc.call(retrieved_region) else retrieved_region end end end end if target.respond_to? :layout_regions @layout_regions = obtain_regions_coordinates(target.layout_regions, driver) @need_convert_layout_regions_coordinates = true unless @layout_regions.empty? end if target.respond_to? :content_regions @content_regions = obtain_regions_coordinates(target.content_regions, driver) @need_convert_content_regions_coordinates = true unless @content_regions.empty? end if target.respond_to? :strict_regions @strict_regions = obtain_regions_coordinates(target.strict_regions, driver) @need_convert_strict_regions_coordinates = true unless @strict_regions.empty? end if target.respond_to? :accessibility_regions @accessibility_regions = obtain_regions_coordinates(target.accessibility_regions, driver) @need_convert_accessibility_regions_coordinates = true unless @accessibility_regions.empty? end # # floating regions return unless target.respond_to? :floating_regions target.floating_regions.each do |r| case r when Proc region, padding_proc = r.call(driver, true) region = selector_regions[target.regions[region]] retrieved_region = Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) floating_region = padding_proc.call(retrieved_region) if padding_proc.is_a? Proc raise Applitools::EyesError.new "Wrong floating region: #{region.class}" unless floating_region.is_a? Applitools::FloatingRegion @floating_regions << floating_region @need_convert_floating_regions_coordinates = true when Applitools::FloatingRegion @floating_regions << r @need_convert_floating_regions_coordinates = true when Applitools::Selenium::VGRegion region = r.region region = selector_regions[target.regions[region]] raise RegionCoordinatesError.new(r, region['error']) if region['error'] retrieved_region = Applitools::Region.new(region['x'], region['y'], region['width'], region['height']) floating_region = r.padding_proc.call(retrieved_region) if r.padding_proc.is_a? Proc raise Applitools::EyesError.new "Wrong floating region: #{region.class}" unless floating_region.is_a? Applitools::FloatingRegion @floating_regions << floating_region @need_convert_floating_regions_coordinates = true end end end |