Class: Applitools::Selenium::Target
- Inherits:
-
Object
- Object
- Applitools::Selenium::Target
- Includes:
- FluentInterface, MatchLevelSetter
- Defined in:
- lib/applitools/selenium/target.rb
Instance Attribute Summary collapse
-
#accessibility_regions ⇒ Object
Returns the value of attribute accessibility_regions.
-
#content_regions ⇒ Object
Returns the value of attribute content_regions.
-
#convert_coordinates_block ⇒ Object
Returns the value of attribute convert_coordinates_block.
-
#coordinate_type ⇒ Object
Returns the value of attribute coordinate_type.
-
#element ⇒ Object
Returns the value of attribute element.
-
#floating_regions ⇒ Object
Returns the value of attribute floating_regions.
-
#frames ⇒ Object
Returns the value of attribute frames.
-
#ignored_regions ⇒ Object
Returns the value of attribute ignored_regions.
-
#layout_regions ⇒ Object
Returns the value of attribute layout_regions.
-
#options ⇒ Object
Returns the value of attribute options.
-
#region_to_check ⇒ Object
Returns the value of attribute region_to_check.
-
#regions ⇒ Object
Returns the value of attribute regions.
-
#strict_regions ⇒ Object
Returns the value of attribute strict_regions.
Class Method Summary collapse
Instance Method Summary collapse
- #accessibility(*args) ⇒ Object
- #before_render_screenshot_hook(hook) ⇒ Object (also: #script_hook, #hooks)
- #content(*args) ⇒ Object
- #convert_coordinates(&block) ⇒ Object
- #default_full_page_for_vg ⇒ Object
- #exact(*args) ⇒ Object
- #finalize ⇒ Object
-
#floating(region_or_element, bounds, left, top, right, bottom, padding) ⇒ Object
Sets the wanted floating region.
- #frame(*args) ⇒ Object
- #fully(value = true) ⇒ Object
-
#ignore(region_or_element, how, what, padding = Applitools::PaddingBounds::PIXEL_PADDING) ⇒ Object
Add the wanted ignored regions.
-
#initialize ⇒ Target
constructor
Initialize a Applitools::Selenium::Target instance.
- #layout(*args) ⇒ Object
- #layout_breakpoints(value = true) ⇒ Object
-
#lazy_load(*args) ⇒ Object
scroll_length, waiting_time, max_amount_to_scroll.
- #page_id(value) ⇒ Object
- #process_region(*args) ⇒ Object
-
#region(element, how, what) ⇒ Applitools::Selenium::Target
Add the desired region.
- #replace_element(original, new, array) ⇒ Object
- #replace_region(original_region, new_region, key) ⇒ Object
- #scroll_root_element(by, what = nil) ⇒ Object
- #send_dom(value = true) ⇒ Object
- #strict(*args) ⇒ Object
- #use_dom(value = true) ⇒ Object
- #variation_group_id(value) ⇒ Object
- #visual_grid_options(value) ⇒ Object
- #wait_before_capture(value) ⇒ Object
Constructor Details
#initialize ⇒ Target
Initialize a Applitools::Selenium::Target instance.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/applitools/selenium/target.rb', line 29 def initialize self.frames = [] self. = { ignore_mismatch: false, script_hooks: { beforeCaptureScreenshot: '' }, visual_grid_options: {} } self.regions = {} self.convert_coordinates_block = nil reset_for_fullscreen end |
Instance Attribute Details
#accessibility_regions ⇒ Object
Returns the value of attribute accessibility_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def accessibility_regions @accessibility_regions end |
#content_regions ⇒ Object
Returns the value of attribute content_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def content_regions @content_regions end |
#convert_coordinates_block ⇒ Object
Returns the value of attribute convert_coordinates_block.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def convert_coordinates_block @convert_coordinates_block end |
#coordinate_type ⇒ Object
Returns the value of attribute coordinate_type.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def coordinate_type @coordinate_type end |
#element ⇒ Object
Returns the value of attribute element.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def element @element end |
#floating_regions ⇒ Object
Returns the value of attribute floating_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def floating_regions @floating_regions end |
#frames ⇒ Object
Returns the value of attribute frames.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def frames @frames end |
#ignored_regions ⇒ Object
Returns the value of attribute ignored_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def ignored_regions @ignored_regions end |
#layout_regions ⇒ Object
Returns the value of attribute layout_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def layout_regions @layout_regions end |
#options ⇒ Object
Returns the value of attribute options.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def @options end |
#region_to_check ⇒ Object
Returns the value of attribute region_to_check.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def region_to_check @region_to_check end |
#regions ⇒ Object
Returns the value of attribute regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def regions @regions end |
#strict_regions ⇒ Object
Returns the value of attribute strict_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def strict_regions @strict_regions end |
Class Method Details
.frame(element) ⇒ Object
9 10 11 |
# File 'lib/applitools/selenium/target.rb', line 9 def frame(element) new.frame(element) end |
.region(*args) ⇒ Object
17 18 19 |
# File 'lib/applitools/selenium/target.rb', line 17 def region(*args) new.region(*args) end |
.window ⇒ Object
13 14 15 |
# File 'lib/applitools/selenium/target.rb', line 13 def window new end |
Instance Method Details
#accessibility(*args) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/applitools/selenium/target.rb', line 248 def accessibility(*args) = Applitools::Utils. args unless [:type] raise Applitools::EyesError, 'You should call Target.accessibility(region, type: type). The :type option is required' end unless Applitools::AccessibilityRegionType.enum_values.include?([:type]) raise Applitools::EyesIllegalArgument, "The region type should be one of [#{Applitools::AccessibilityRegionType.enum_values.join(', ')}]" end handle_frames padding_proc = proc { |region| Applitools::AccessibilityRegion.new(region, [:type]) } accessibility_regions << case args.first when ::Selenium::WebDriver::Element proc do |driver, return_element = false| element = applitools_element_from_selenium_element(driver, args.first) next element, padding_proc if return_element padding_proc.call(element) end when Applitools::Selenium::Element proc do |_driver, return_element = false| next args.first, padding_proc if return_element padding_proc.call(args.first) end when Applitools::Region Applitools::AccessibilityRegion.new( args.first, [:type] ) when String proc do |driver, return_element = false| element = driver.find_element(name_or_id: args.first) next element, padding_proc if return_element padding_proc.call(element) end when :css # (:css, '.ignore', type: 'LargeText') { region: args[1], type: [:type] } else proc do |driver, return_element = false| elements = driver.find_elements(*args) next elements, padding_proc if return_element elements.map { |e| padding_proc.call(e) } end end self end |
#before_render_screenshot_hook(hook) ⇒ Object Also known as: script_hook, hooks
229 230 231 232 233 234 235 236 |
# File 'lib/applitools/selenium/target.rb', line 229 def before_render_screenshot_hook(hook) if hook.is_a?(Hash) && hook[:beforeCaptureScreenshot] [:script_hooks] = hook else [:script_hooks][:beforeCaptureScreenshot] = hook end self end |
#content(*args) ⇒ Object
103 104 105 106 107 |
# File 'lib/applitools/selenium/target.rb', line 103 def content(*args) region = region_from_args(args) content_regions << region if region self end |
#convert_coordinates(&block) ⇒ Object
314 315 316 |
# File 'lib/applitools/selenium/target.rb', line 314 def convert_coordinates(&block) self.convert_coordinates_block = block end |
#default_full_page_for_vg ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/applitools/selenium/target.rb', line 297 def default_full_page_for_vg # if options[:stitch_content].nil? # case region_to_check # when nil # fully(true) # when Proc # begin # r = region_to_check.call # # fully(true) if r == Applitools::Region::EMPTY # rescue StandardError # fully(false) # end # end # end nil end |
#exact(*args) ⇒ Object
115 116 117 |
# File 'lib/applitools/selenium/target.rb', line 115 def exact(*args) match_level(Applitools::MatchLevel::EXACT, *args) end |
#finalize ⇒ Object
241 242 243 244 245 246 |
# File 'lib/applitools/selenium/target.rb', line 241 def finalize return self unless frame_or_element region = frame_or_element self.frame_or_element = nil dup.region(region) end |
#floating(region_or_element, bounds, left, top, right, bottom, padding) ⇒ Object
Sets the wanted floating region
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/applitools/selenium/target.rb', line 81 def floating(*args) = Applitools::Utils.(args) padding = && [:padding] requested_padding = get_requested_padding(padding, args) bounds = get_bounds(args) value = convert_to_universal(args) value = { type: args[0], selector: args[1] } if value.nil? value = value[:selector] if value.is_a?(Hash) && (value[:type].to_s === 'id') region = { region: value } region.merge!(bounds) if bounds != {} region.merge!(padding: requested_padding) if requested_padding != {} region.merge!(regionId: [:region_id]) if [:region_id] floating_regions << region self end |
#frame(*args) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/applitools/selenium/target.rb', line 182 def frame(*args) element = case args.first when ::Selenium::WebDriver::Element, Applitools::Selenium::Element, String args.first else proc { |d| d.find_element(*args) } end frames << element # frames << frame_or_element if frame_or_element # self.frame_or_element = element reset_for_fullscreen self end |
#fully(value = true) ⇒ Object
170 171 172 173 174 |
# File 'lib/applitools/selenium/target.rb', line 170 def fully(value = true) [:stitch_content] = value ? true : false handle_frames self end |
#ignore(region_or_element, how, what, padding = Applitools::PaddingBounds::PIXEL_PADDING) ⇒ Object
Add the wanted ignored regions.
48 49 50 51 52 53 54 55 56 |
# File 'lib/applitools/selenium/target.rb', line 48 def ignore(*args) if args.empty? reset_ignore else region = region_from_args(args) ignored_regions << region if region end self end |
#layout(*args) ⇒ Object
97 98 99 100 101 |
# File 'lib/applitools/selenium/target.rb', line 97 def layout(*args) region = region_from_args(args) layout_regions << region if region self end |
#layout_breakpoints(value = true) ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/applitools/selenium/target.rb', line 331 def layout_breakpoints(value = true) if value.is_a?(Hash) && (value.has_key?(:breakpoints) || value.has_key?('breakpoints')) [:layout_breakpoints] = value else [:layout_breakpoints] = { breakpoints: value } end self end |
#lazy_load(*args) ⇒ Object
scroll_length, waiting_time, max_amount_to_scroll
352 353 354 355 |
# File 'lib/applitools/selenium/target.rb', line 352 def lazy_load(*args) # scroll_length, waiting_time, max_amount_to_scroll [:lazy_load] = args.is_a?(Hash) ? args : true self end |
#page_id(value) ⇒ Object
346 347 348 349 350 |
# File 'lib/applitools/selenium/target.rb', line 346 def page_id(value) Applitools::ArgumentGuard.not_nil(value, 'page_id') [:page_id] = value self end |
#process_region(*args) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/applitools/selenium/target.rb', line 125 def process_region(*args) r = args.first case r when ::Selenium::WebDriver::Element proc do |driver| applitools_element_from_selenium_element(driver, args.dup.first) end when Applitools::Region, Applitools::Selenium::Element proc { r } else proc do |driver| args_dup = args.dup driver.find_element(args_dup.shift, args_dup.shift) end end end |
#region(element, how, what) ⇒ Applitools::Selenium::Target
Add the desired region.
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/applitools/selenium/target.rb', line 207 def region(*args) value = convert_to_universal(args) value = { type: args[0], selector: args[1] } if value.nil? value = value[:selector] if value.is_a?(Hash) && (value[:type].to_s === 'id') self.region_to_check = value self.coordinate_type = Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative] [:timeout] = nil reset_ignore reset_floating self end |
#replace_element(original, new, array) ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/applitools/selenium/target.rb', line 159 def replace_element(original, new, array) case new when Array index = array.index(original) array.delete_at(index) array.insert(index, *new) when Applitools::Selenium::VGRegion array[array.index(original)] = new end end |
#replace_region(original_region, new_region, key) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/applitools/selenium/target.rb', line 142 def replace_region(original_region, new_region, key) case key when :content_regions replace_element(original_region, new_region, content_regions) when :strict_regions replace_element(original_region, new_region, strict_regions) when :layout_regions replace_element(original_region, new_region, layout_regions) when :floating replace_element(original_region, new_region, floating_regions) when :ignore replace_element(original_region, new_region, ignored_regions) when :accessibility_regions replace_element(original_region, new_region, accessibility_regions) end end |
#scroll_root_element(by, what = nil) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/applitools/selenium/target.rb', line 318 def scroll_root_element(by, what = nil) [:scroll_root_element] = if is_element?(by) ref = by.ref ref = by.ref[1] if ref.is_a?(Array) && ref[0] === :element { elementId: ref } elsif what { type: by.to_s, selector: what } else by end self end |
#send_dom(value = true) ⇒ Object
219 220 221 222 |
# File 'lib/applitools/selenium/target.rb', line 219 def send_dom(value = true) [:send_dom] = value ? true : false self end |
#strict(*args) ⇒ Object
109 110 111 112 113 |
# File 'lib/applitools/selenium/target.rb', line 109 def strict(*args) region = region_from_args(args) strict_regions << region if region self end |
#use_dom(value = true) ⇒ Object
224 225 226 227 |
# File 'lib/applitools/selenium/target.rb', line 224 def use_dom(value = true) [:use_dom] = value ? true : false self end |
#variation_group_id(value) ⇒ Object
176 177 178 179 180 |
# File 'lib/applitools/selenium/target.rb', line 176 def variation_group_id(value) Applitools::ArgumentGuard.not_nil(value, 'variation_group_id') [:variation_group_id] = value self end |
#visual_grid_options(value) ⇒ Object
119 120 121 122 123 |
# File 'lib/applitools/selenium/target.rb', line 119 def (value) Applitools::ArgumentGuard.hash(value, 'value') [:visual_grid_options] = value self end |
#wait_before_capture(value) ⇒ Object
340 341 342 343 344 |
# File 'lib/applitools/selenium/target.rb', line 340 def wait_before_capture(value) Applitools::ArgumentGuard.not_nil(value, 'wait_before_capture') [:wait_before_capture] = value self end |