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.
-
#dynamic_regions ⇒ Object
Returns the value of attribute dynamic_regions.
-
#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
- #dynamic(*args) ⇒ 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, reload: nil, height_breakpoints: nil) ⇒ 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 40 41 42 43 44 45 46 47 48 |
# File 'lib/applitools/selenium/target.rb', line 29 def initialize self.frames = [] self. = { ignore_mismatch: false, ignore_caret: nil, script_hooks: { beforeCaptureScreenshot: '' }, visual_grid_options: {} } self.regions = {} self.accessibility_regions = [] self.dynamic_regions = [] self.ignored_regions = [] self.floating_regions = [] self.layout_regions = [] self.content_regions = [] self.strict_regions = [] self.convert_coordinates_block = nil self.frame_or_element = 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 |
#dynamic_regions ⇒ Object
Returns the value of attribute dynamic_regions.
22 23 24 |
# File 'lib/applitools/selenium/target.rb', line 22 def dynamic_regions @dynamic_regions 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
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 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/applitools/selenium/target.rb', line 260 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 { 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
241 242 243 244 245 246 247 248 |
# File 'lib/applitools/selenium/target.rb', line 241 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
112 113 114 115 116 |
# File 'lib/applitools/selenium/target.rb', line 112 def content(*args) region = region_from_args(args) content_regions << region if region self end |
#convert_coordinates(&block) ⇒ Object
369 370 371 |
# File 'lib/applitools/selenium/target.rb', line 369 def convert_coordinates(&block) self.convert_coordinates_block = block end |
#default_full_page_for_vg ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/applitools/selenium/target.rb', line 352 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 |
#dynamic(*args) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/applitools/selenium/target.rb', line 307 def dynamic(*args) = Applitools::Utils. args handle_frames padding = && [:padding] requested_padding = get_requested_padding(padding, args) padding_proc = proc do |region| dynamic_region = Applitools::DynamicRegion.new(region, [:type]) dynamic_region.padding(Applitools::PaddingBounds.new(**requested_padding)) if requested_padding != {} dynamic_region end dynamic_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 dynamic_region = Applitools::DynamicRegion.new(args.first, [:type]) dynamic_region.padding(Applitools::PaddingBounds.new(**requested_padding)) if requested_padding != {} dynamic_region 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 { 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 |
#exact(*args) ⇒ Object
124 125 126 127 |
# File 'lib/applitools/selenium/target.rb', line 124 def exact(*args) match_level(:exact, *args) self end |
#finalize ⇒ Object
253 254 255 256 257 258 |
# File 'lib/applitools/selenium/target.rb', line 253 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/applitools/selenium/target.rb', line 90 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 != {} apply_region_id(region, value, ) floating_regions << region self end |
#frame(*args) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/applitools/selenium/target.rb', line 194 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
182 183 184 185 186 |
# File 'lib/applitools/selenium/target.rb', line 182 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.
57 58 59 60 61 62 63 64 65 |
# File 'lib/applitools/selenium/target.rb', line 57 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
106 107 108 109 110 |
# File 'lib/applitools/selenium/target.rb', line 106 def layout(*args) region = region_from_args(args) layout_regions << region if region self end |
#layout_breakpoints(value = true, reload: nil, height_breakpoints: nil) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/applitools/selenium/target.rb', line 386 def layout_breakpoints(value = true, reload: nil, height_breakpoints: nil) if value.is_a?(Hash) && (value.has_key?(:breakpoints) || value.has_key?('breakpoints')) [:layout_breakpoints] = value # Set defaults for the new options if they're not in the hash # Need to check both symbol and string keys [:layout_breakpoints][:reload] = value[:reload] || value['reload'] || reload [:layout_breakpoints][:height_breakpoints] = value[:height_breakpoints] || value['height_breakpoints'] || height_breakpoints else [:layout_breakpoints] = { breakpoints: value, reload: reload, height_breakpoints: height_breakpoints } end self end |
#lazy_load(*args) ⇒ Object
scroll_length, waiting_time, max_amount_to_scroll
416 417 418 419 |
# File 'lib/applitools/selenium/target.rb', line 416 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
410 411 412 413 414 |
# File 'lib/applitools/selenium/target.rb', line 410 def page_id(value) Applitools::ArgumentGuard.not_nil(value, 'page_id') [:page_id] = value self end |
#process_region(*args) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/applitools/selenium/target.rb', line 135 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.
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/applitools/selenium/target.rb', line 219 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 = :context_relative [:timeout] = nil reset_ignore reset_floating self end |
#replace_element(original, new, array) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/applitools/selenium/target.rb', line 171 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/applitools/selenium/target.rb', line 152 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) when :dynamic_regions replace_element(original_region, new_region, dynamic_regions) end end |
#scroll_root_element(by, what = nil) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/applitools/selenium/target.rb', line 373 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
231 232 233 234 |
# File 'lib/applitools/selenium/target.rb', line 231 def send_dom(value = true) [:send_dom] = value ? true : false self end |
#strict(*args) ⇒ Object
118 119 120 121 122 |
# File 'lib/applitools/selenium/target.rb', line 118 def strict(*args) region = region_from_args(args) strict_regions << region if region self end |
#use_dom(value = true) ⇒ Object
236 237 238 239 |
# File 'lib/applitools/selenium/target.rb', line 236 def use_dom(value = true) [:use_dom] = value ? true : false self end |
#variation_group_id(value) ⇒ Object
188 189 190 191 192 |
# File 'lib/applitools/selenium/target.rb', line 188 def variation_group_id(value) Applitools::ArgumentGuard.not_nil(value, 'variation_group_id') [:variation_group_id] = value self end |
#visual_grid_options(value) ⇒ Object
129 130 131 132 133 |
# File 'lib/applitools/selenium/target.rb', line 129 def (value) Applitools::ArgumentGuard.hash(value, 'value') [:visual_grid_options] = value self end |
#wait_before_capture(value) ⇒ Object
404 405 406 407 408 |
# File 'lib/applitools/selenium/target.rb', line 404 def wait_before_capture(value) Applitools::ArgumentGuard.not_nil(value, 'wait_before_capture') [:wait_before_capture] = value self end |