Class: Applitools::Selenium::Target
- Inherits:
-
Object
- Object
- Applitools::Selenium::Target
- Includes:
- FluentInterface
- Defined in:
- lib/applitools/selenium/target.rb
Instance Attribute Summary collapse
-
#content_regions ⇒ Object
Returns the value of attribute content_regions.
-
#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.
-
#match_level(*args) ⇒ Object
Returns the value of attribute match_level.
-
#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
- #content(*args) ⇒ Object
- #exact(*args) ⇒ Object
- #finalize ⇒ Object
-
#floating(region_or_element, bounds, left, top, right, bottom, padding) ⇒ Object
Sets the wanted floating region.
- #frame(element) ⇒ 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
- #process_region(*args) ⇒ Object
-
#region(element, how, what) ⇒ Applitools::Selenium::Target
Add the desired region.
- #script_hook(hook) ⇒ Object
- #send_dom(value = true) ⇒ Object
- #strict(*args) ⇒ Object
- #use_dom(value = true) ⇒ Object
Constructor Details
#initialize ⇒ Target
Initialize a Applitools::Selenium::Target instance.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/applitools/selenium/target.rb', line 28 def initialize self.frames = [] self. = { ignore_caret: true, ignore_mismatch: false, send_dom: nil, script_hooks: { beforeCaptureScreenshot: '' } } self.regions = {} reset_for_fullscreen end |
Instance Attribute Details
#content_regions ⇒ Object
Returns the value of attribute content_regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def content_regions @content_regions end |
#coordinate_type ⇒ Object
Returns the value of attribute coordinate_type.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def coordinate_type @coordinate_type end |
#element ⇒ Object
Returns the value of attribute element.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def element @element end |
#floating_regions ⇒ Object
Returns the value of attribute floating_regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def floating_regions @floating_regions end |
#frames ⇒ Object
Returns the value of attribute frames.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def frames @frames end |
#ignored_regions ⇒ Object
Returns the value of attribute ignored_regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def ignored_regions @ignored_regions end |
#layout_regions ⇒ Object
Returns the value of attribute layout_regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def layout_regions @layout_regions end |
#match_level(*args) ⇒ Object
Returns the value of attribute match_level.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def match_level @match_level end |
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def end |
#region_to_check ⇒ Object
Returns the value of attribute region_to_check.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def region_to_check @region_to_check end |
#regions ⇒ Object
Returns the value of attribute regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def regions @regions end |
#strict_regions ⇒ Object
Returns the value of attribute strict_regions.
21 22 23 |
# File 'lib/applitools/selenium/target.rb', line 21 def strict_regions @strict_regions end |
Class Method Details
.frame(element) ⇒ Object
8 9 10 |
# File 'lib/applitools/selenium/target.rb', line 8 def frame(element) new.frame(element) end |
.region(*args) ⇒ Object
16 17 18 |
# File 'lib/applitools/selenium/target.rb', line 16 def region(*args) new.region(*args) end |
.window ⇒ Object
12 13 14 |
# File 'lib/applitools/selenium/target.rb', line 12 def window new end |
Instance Method Details
#content(*args) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/applitools/selenium/target.rb', line 155 def content(*args) return match_level(Applitools::MatchLevel::CONTENT) if args.empty? region = process_region(*args) content_regions << region self end |
#exact(*args) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/applitools/selenium/target.rb', line 169 def exact(*args) return match_level(Applitools::MatchLevel::EXACT) if args.empty? raise Applitools::EyesError('Target.exact() is supposed to be called without args!') # region = process_region(args) # exact_regions << region # self end |
#finalize ⇒ Object
255 256 257 258 259 260 |
# File 'lib/applitools/selenium/target.rb', line 255 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/applitools/selenium/target.rb', line 110 def floating(*args) requested_padding = if args.last.is_a? Applitools::PaddingBounds args.pop else Applitools::PaddingBounds::PIXEL_PADDING end value = case args.first when Applitools::FloatingRegion args.first.padding(requested_padding) when ::Applitools::Region Applitools::FloatingRegion.any(args.shift, *args).padding(requested_padding) when ::Selenium::WebDriver::Element, Applitools::Selenium::Element proc do |_driver, return_element = false| args_dup = args.dup region = args_dup.shift padding_proc = proc do |region| Applitools::FloatingRegion.any(region, *args_dup).padding(requested_padding) end next region, padding_proc if return_element padding_proc.call(region) end else proc do |driver, return_element = false| args_dup = args.dup region = driver.find_element(args_dup.shift, args_dup.shift) padding_proc = proc do |region| Applitools::FloatingRegion.any( region, *args_dup ).padding(requested_padding) end next region, padding_proc if return_element padding_proc.call(region) end end floating_regions << value self end |
#frame(element) ⇒ Object
201 202 203 204 205 206 |
# File 'lib/applitools/selenium/target.rb', line 201 def frame(element) frames << frame_or_element if frame_or_element self.frame_or_element = element reset_for_fullscreen self end |
#fully(value = true) ⇒ Object
195 196 197 198 199 |
# File 'lib/applitools/selenium/target.rb', line 195 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.
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 |
# File 'lib/applitools/selenium/target.rb', line 47 def ignore(*args) if args.empty? reset_ignore else requested_padding = if args.last.is_a? Applitools::PaddingBounds args.pop else Applitools::PaddingBounds::PIXEL_PADDING end ignored_regions << case args.first when Applitools::Region proc { args.first.padding(requested_padding) } when Applitools::Selenium::Element, ::Selenium::WebDriver::Element proc do |_driver, return_element = false| region = args.first padding_proc = proc do |region| Applitools::Region.from_location_size( region.location, region.size ).padding(requested_padding) end next region, padding_proc if return_element padding_proc.call(region) end else proc do |driver, return_element = false| region = driver.find_element(*args) padding_proc = proc do |region| Applitools::Region.from_location_size( region.location, region.size ).padding(requested_padding) end next region, padding_proc if return_element padding_proc.call(region) end end end self end |
#layout(*args) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/applitools/selenium/target.rb', line 148 def layout(*args) return match_level(Applitools::MatchLevel::LAYOUT) if args.empty? region = process_region(*args) layout_regions << region self end |
#process_region(*args) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/applitools/selenium/target.rb', line 177 def process_region(*args) r = args.first case r when Applitools::Region, ::Selenium::WebDriver::Element, 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 230 231 232 233 234 235 236 237 238 |
# File 'lib/applitools/selenium/target.rb', line 219 def region(*args) handle_frames self.region_to_check = case args.first when Applitools::Selenium::Element, Applitools::Region, ::Selenium::WebDriver::Element proc { args.first } when String proc do |driver| driver.find_element(name_or_id: args.first) end else proc do |driver| driver.find_element(*args) end end self.coordinate_type = Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative] [:timeout] = nil reset_ignore reset_floating self end |
#script_hook(hook) ⇒ Object
250 251 252 253 |
# File 'lib/applitools/selenium/target.rb', line 250 def script_hook(hook) [:script_hooks][:beforeCaptureScreenshot] = hook self end |
#send_dom(value = true) ⇒ Object
240 241 242 243 |
# File 'lib/applitools/selenium/target.rb', line 240 def send_dom(value = true) [:send_dom] = value ? true : false self end |
#strict(*args) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/applitools/selenium/target.rb', line 162 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
245 246 247 248 |
# File 'lib/applitools/selenium/target.rb', line 245 def use_dom(value = true) [:use_dom] = value ? true : false self end |