Class: Applitools::UniversalCheckSettings

Inherits:
Object
  • Object
show all
Includes:
Jsonable
Defined in:
lib/applitools/universal_sdk/universal_check_settings.rb

Instance Method Summary collapse

Methods included from Jsonable

included, #json, #json_data

Constructor Details

#initialize(*args) ⇒ UniversalCheckSettings

Returns a new instance of UniversalCheckSettings.



100
101
102
103
104
105
# File 'lib/applitools/universal_sdk/universal_check_settings.rb', line 100

def initialize(*args)
  options = Applitools::Utils.extract_options! args
  options.keys.select {|k| options[k] && respond_to?("#{k}=") }.each {|k| send("#{k}=", options[k]) }

  # self.timeout = Applitools::Connectivity::ServerConnector::DEFAULT_TIMEOUT
end

Instance Method Details

#from_eyes_images(target, eyes) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/applitools/universal_sdk/universal_check_settings.rb', line 192

def from_eyes_images(target, eyes)
  self.accessibility_settings = eyes.accessibility_validation
  self.disable_browser_fetching = eyes.dont_fetch_resources
  self.accessibility_regions = target.accessibility_regions
  self.floating_regions = target.floating_regions

  self.ignore_regions = target.ignored_regions.map do |ir|
    ir.is_a?(Proc) ? normalize_element_selector(ir.call(eyes.driver)) : ir
  end

  if target.region_to_check.is_a?(Hash)
    self.region = target.region_to_check
  elsif target.region_to_check.is_a?(String)
    self.region = target.region_to_check
  elsif target.region_to_check.is_a?(Proc)
    el = target.region_to_check.call(eyes.driver)
    self.region = normalize_element_selector(el) unless el.respond_to?(:empty?) && el.empty?
  end

  self.exact = (target.options[:exact] && target.options[:exact].to_hash) || (eyes.exact && eyes.exact.to_hash)

  self.image = target.image
end

#from_original_target(target, eyes) ⇒ Object



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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/applitools/universal_sdk/universal_check_settings.rb', line 117

def from_original_target(target, eyes)
  # require('pry')
  # binding.pry
  return from_eyes_images(target, eyes) if eyes.class.name === 'Applitools::Images::Eyes'

  self.accessibility_settings = eyes.accessibility_validation
  self.disable_browser_fetching = eyes.dont_fetch_resources
  self.screenshot_mode = eyes.screenshot_mode

  self.accessibility_regions = target.accessibility_regions
  self.content_regions = target.content_regions
  self.floating_regions = target.floating_regions

  if target.respond_to?(:frames)
    self.frames = target.frames.map do |f|
      f = f.call(eyes.driver) if f.is_a?(Proc)
      normalize_element_selector(f)
    end
  end

  self.fully = target.options[:stitch_content]
  self.hooks = target.options[:script_hooks]

  # require('pry')
  # binding.pry

  self.ignore_regions = target.ignored_regions.map do |ir|
    ir.is_a?(Proc) ? normalize_element_selector(ir.call(eyes.driver)) : ir
  end
  # self.ignore_regions = target.ignored_regions
  self.layout_regions = target.layout_regions.map do |lr|
    lr.is_a?(Proc) ? normalize_element_selector(lr.call(eyes.driver)) : lr
  end

  if target.region_to_check.is_a?(Hash)
    self.region = target.region_to_check
  elsif target.region_to_check.is_a?(String)
    self.region = target.region_to_check
  elsif target.region_to_check.is_a?(Proc)
    # require('pry')
    # binding.pry
    el = target.region_to_check.call(eyes.driver)
    self.region = normalize_element_selector(el) unless el.respond_to?(:empty?) && el.empty?
  end
  # self.region = normalize_element_selector(target.region_to_check.call(eyes.driver))
  # self.region = nil if region.empty?

  self.strict_regions = target.strict_regions
  self.timeout = target.options[:timeout]
  self.variation_group_id = target.options[:variation_group_id]
  self.wait_before_capture = target.options[:wait_before_capture]
  self.lazy_load = target.options[:lazy_load]
  self.webview = target.options[:webview]
  self.page_id = target.options[:page_id]

  self.scroll_root_element = target.options[:scroll_root_element] || eyes.scroll_root_element
  self.layout_breakpoints = target.options[:layout_breakpoints] || eyes.layout_breakpoints

  self.exact = (target.options[:exact] && target.options[:exact].to_hash) || (eyes.exact && eyes.exact.to_hash)
  self.enable_patterns = from_target_options_or_eyes(:enable_patterns, target.options, eyes)
  self.ignore_caret = from_target_options_or_eyes(:ignore_caret, target.options, eyes)
  self.ignore_displacements = from_target_options_or_eyes(:ignore_displacements, target.options, eyes)
  self.match_level = from_target_options_or_eyes(:match_level, target.options, eyes)
  self.send_dom = from_target_options_or_eyes(:send_dom, target.options, eyes)
  self.use_dom = from_target_options_or_eyes(:use_dom, target.options, eyes)
  self.visual_grid_options = from_target_options_or_eyes(:visual_grid_options, target.options, eyes)
  self.ufg_options = self.visual_grid_options
  self.user_command_id = self.variation_group_id

  self.image = target.image if target.respond_to?(:image)
# rescue => e
#   require('pry')
#   binding.pry
end

#normalize_element_selector(element) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/applitools/universal_sdk/universal_check_settings.rb', line 107

def normalize_element_selector(element)
  if element.is_a?(::Selenium::WebDriver::Element) || element.is_a?(Applitools::Selenium::Element)
    ref = element.ref
    ref = element.ref[1] if ref.is_a?(Array) && ref[0] === :element
    return { elementId: ref }
  else
    element
  end
end

#to_hashObject



216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/applitools/universal_sdk/universal_check_settings.rb', line 216

def to_hash
  json_data.compact.reject do |_, v|
    case v
      when Array, Hash
        v.empty?
      when Numeric
        v.zero?
      # when FalseClass
      #   true
      else
        false
    end
  end
end