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
- #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
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
247 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 |
# File 'lib/applitools/selenium/target.rb', line 247 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
228 229 230 231 232 233 234 235 |
# File 'lib/applitools/selenium/target.rb', line 228 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
100 101 102 103 104 105 |
# File 'lib/applitools/selenium/target.rb', line 100 def content(*args) return match_level(Applitools::MatchLevel::CONTENT) if args.empty? region = process_region(*args) content_regions << region self end |
#convert_coordinates(&block) ⇒ Object
313 314 315 |
# File 'lib/applitools/selenium/target.rb', line 313 def convert_coordinates(&block) self.convert_coordinates_block = block end |
#default_full_page_for_vg ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/applitools/selenium/target.rb', line 296 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
114 115 116 |
# File 'lib/applitools/selenium/target.rb', line 114 def exact(*args) match_level(Applitools::MatchLevel::EXACT, *args) end |
#finalize ⇒ Object
240 241 242 243 244 245 |
# File 'lib/applitools/selenium/target.rb', line 240 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
83 84 85 86 87 88 89 90 91 |
# File 'lib/applitools/selenium/target.rb', line 83 def floating(*args) requested_padding = get_requested_padding(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') value = { region: value }.merge(requested_padding) floating_regions << value self end |
#frame(*args) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/applitools/selenium/target.rb', line 181 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
169 170 171 172 173 |
# File 'lib/applitools/selenium/target.rb', line 169 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 57 58 |
# File 'lib/applitools/selenium/target.rb', line 48 def ignore(*args) if args.empty? reset_ignore else 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') ignored_regions << value end self end |
#layout(*args) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/applitools/selenium/target.rb', line 93 def layout(*args) return match_level(Applitools::MatchLevel::LAYOUT) if args.empty? region = process_region(*args) layout_regions << region self end |
#layout_breakpoints(value = true) ⇒ Object
330 331 332 333 |
# File 'lib/applitools/selenium/target.rb', line 330 def layout_breakpoints(value = true) [:layout_breakpoints] = value.is_a?(Array) ? value : value self end |
#process_region(*args) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/applitools/selenium/target.rb', line 124 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.
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/applitools/selenium/target.rb', line 206 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
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/applitools/selenium/target.rb', line 158 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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/applitools/selenium/target.rb', line 141 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
317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/applitools/selenium/target.rb', line 317 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
218 219 220 221 |
# File 'lib/applitools/selenium/target.rb', line 218 def send_dom(value = true) [:send_dom] = value ? true : false self end |
#strict(*args) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/applitools/selenium/target.rb', line 107 def strict(*args) return match_level(Applitools::MatchLevel::STRICT) if args.empty? region = process_region(*args) strict_regions << region self end |
#use_dom(value = true) ⇒ Object
223 224 225 226 |
# File 'lib/applitools/selenium/target.rb', line 223 def use_dom(value = true) [:use_dom] = value ? true : false self end |
#variation_group_id(value) ⇒ Object
175 176 177 178 179 |
# File 'lib/applitools/selenium/target.rb', line 175 def variation_group_id(value) Applitools::ArgumentGuard.not_nil(value, 'variation_group_id') [:variation_group_id] = value self end |
#visual_grid_options(value) ⇒ Object
118 119 120 121 122 |
# File 'lib/applitools/selenium/target.rb', line 118 def (value) Applitools::ArgumentGuard.hash(value, 'value') [:visual_grid_options] = value self end |