Class: Applitools::EyesBaseConfiguration

Inherits:
AbstractConfiguration show all
Defined in:
lib/applitools/core/eyes_base_configuration.rb

Constant Summary collapse

DEFAULT_MATCH_TIMEOUT =

seconds

0
DEFAULT_CONFIG =
{
  branch_name: ENV['APPLITOOLS_BRANCH'],
  parent_branch_name: ENV['APPLITOOLS_PARENT_BRANCH'],
  baseline_branch_name: ENV['APPLITOOLS_BASELINE_BRANCH'],
  save_diffs: false,
  server_url: ENV['APPLITOOLS_SERVER_URL'] ||
    ENV['bamboo_APPLITOOLS_SERVER_URL'] || Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL,
  api_key: ENV['APPLITOOLS_API_KEY'] || ENV['bamboo_APPLITOOLS_API_KEY'] || '',
  save_new_tests: true,
  default_match_settings: Applitools::ImageMatchSettings.new,
  accessibility_validation: nil,
  properties: [],
  match_timeout: DEFAULT_MATCH_TIMEOUT,
  dont_fetch_resources: true,
  enable_cross_origin_rendering: true,
  dont_use_cookies: false,
}.freeze

Instance Attribute Summary

Attributes inherited from AbstractConfiguration

#config_hash, #validation_errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractConfiguration

#deep_clone

Methods included from EyesConfigurationDSL

#accessor_methods, #boolean_field, #collect_method, #enum_field, #int_field, #methods_to_delegate, #object_field, #string_field

Constructor Details

#initializeEyesBaseConfiguration

Returns a new instance of EyesBaseConfiguration.



40
41
42
43
# File 'lib/applitools/core/eyes_base_configuration.rb', line 40

def initialize
  super
  # self.batch_info = Applitools::BatchInfo.new
end

Class Method Details

.default_configObject



35
36
37
# File 'lib/applitools/core/eyes_base_configuration.rb', line 35

def default_config
  DEFAULT_CONFIG
end

Instance Method Details

#add_property(name, value) ⇒ Object



200
201
202
# File 'lib/applitools/core/eyes_base_configuration.rb', line 200

def add_property(name, value)
  properties << { name: name, value: value } if name && value
end

#batchObject



81
82
83
84
85
86
87
# File 'lib/applitools/core/eyes_base_configuration.rb', line 81

def batch
  if batch_info.nil?
    Applitools::EyesLogger.info 'No batch set'
    self.batch_info = BatchInfo.new
  end
  batch_info
end

#batch=(value) ⇒ Object



89
90
91
# File 'lib/applitools/core/eyes_base_configuration.rb', line 89

def batch=(value)
  self.batch_info = value
end

#config_keysObject



58
59
60
# File 'lib/applitools/core/eyes_base_configuration.rb', line 58

def config_keys
  config_hash.keys
end

#custom_getter_for_exact(_value) ⇒ Object



171
172
173
# File 'lib/applitools/core/eyes_base_configuration.rb', line 171

def custom_getter_for_exact(_value)
  default_match_settings.exact
end

#custom_getter_for_ignore_caret(_value) ⇒ Object



187
188
189
# File 'lib/applitools/core/eyes_base_configuration.rb', line 187

def custom_getter_for_ignore_caret(_value)
  default_match_settings.ignore_caret
end

#custom_getter_for_ignore_displacements(_value) ⇒ Object



167
168
169
# File 'lib/applitools/core/eyes_base_configuration.rb', line 167

def custom_getter_for_ignore_displacements(_value)
  default_match_settings.ignore_displacements
end

#custom_getter_for_match_level(_value) ⇒ Object



183
184
185
# File 'lib/applitools/core/eyes_base_configuration.rb', line 183

def custom_getter_for_match_level(_value)
  default_match_settings.match_level
end

#custom_getter_for_remainder(_value) ⇒ Object



179
180
181
# File 'lib/applitools/core/eyes_base_configuration.rb', line 179

def custom_getter_for_remainder(_value)
  default_match_settings.remainder
end

#custom_getter_for_scale(_value) ⇒ Object



175
176
177
# File 'lib/applitools/core/eyes_base_configuration.rb', line 175

def custom_getter_for_scale(_value)
  default_match_settings.scale
end

#custom_setter_for_accessibility_validation(value) ⇒ Object



195
196
197
198
# File 'lib/applitools/core/eyes_base_configuration.rb', line 195

def custom_setter_for_accessibility_validation(value)
  # self.default_match_settings = self.parent.class.default_config[:default_match_settings] unless default_match_settings
  default_match_settings.accessibility_validation = value
end

#custom_setter_for_exact(value) ⇒ Object



147
148
149
# File 'lib/applitools/core/eyes_base_configuration.rb', line 147

def custom_setter_for_exact(value)
  default_match_settings.exact = value
end

#custom_setter_for_ignore_caret(value) ⇒ Object



191
192
193
# File 'lib/applitools/core/eyes_base_configuration.rb', line 191

def custom_setter_for_ignore_caret(value)
  default_match_settings.ignore_caret = value
end

#custom_setter_for_ignore_displacements(value) ⇒ Object



163
164
165
# File 'lib/applitools/core/eyes_base_configuration.rb', line 163

def custom_setter_for_ignore_displacements(value)
  default_match_settings.ignore_displacements = value
end

#custom_setter_for_match_level(value) ⇒ Object



151
152
153
# File 'lib/applitools/core/eyes_base_configuration.rb', line 151

def custom_setter_for_match_level(value)
  default_match_settings.match_level = value
end

#custom_setter_for_remainder(value) ⇒ Object



159
160
161
# File 'lib/applitools/core/eyes_base_configuration.rb', line 159

def custom_setter_for_remainder(value)
  default_match_settings.remainder = value
end

#custom_setter_for_scale(value) ⇒ Object



155
156
157
# File 'lib/applitools/core/eyes_base_configuration.rb', line 155

def custom_setter_for_scale(value)
  default_match_settings.scale = value
end

#disable_browser_fetching=(value) ⇒ Object



204
205
206
# File 'lib/applitools/core/eyes_base_configuration.rb', line 204

def disable_browser_fetching=(value)
  self.dont_fetch_resources = value
end

#layout_breakpoints(value = nil, reload: nil, height_breakpoints: nil) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/applitools/core/eyes_base_configuration.rb', line 229

def layout_breakpoints(value = nil, reload: nil, height_breakpoints: nil)
  if value.nil?
    config_hash[:layout_breakpoints]
  else
    if value.is_a?(Hash)
      # If it's already a hash, add our options if not present
      # Need to check both symbol and string keys
      value[:layout_breakpoints][:reload] = value[:reload] || value['reload'] || reload
      value[:layout_breakpoints][:height_breakpoints] = value[:height_breakpoints] || value['height_breakpoints'] || height_breakpoints
      self.layout_breakpoints = value
    else
      # For non-hash values, create a hash with all options
      self.layout_breakpoints = {
        breakpoints: value,
        reload: reload,
        height_breakpoints: height_breakpoints
      }
    end
    self
  end
end

#layout_breakpoints=(value) ⇒ Object

layoutBreakpoints?: boolean | number[]



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/applitools/core/eyes_base_configuration.rb', line 215

def layout_breakpoints=(value)
  if value === true || value === false
    config_hash[:layout_breakpoints] = { breakpoints: value }
  elsif value.is_a?(Array) && value.all? {|v| v.is_a?(Numeric)}
    config_hash[:layout_breakpoints] = { breakpoints: value }
  elsif value.is_a?(Hash)
    if value.has_key?(:breakpoints) || value.has_key?('breakpoints')
      config_hash[:layout_breakpoints] = value
    else
      config_hash[:layout_breakpoints] = { breakpoints: value }
    end
  end
end

#merge(other_config) ⇒ Object



45
46
47
48
49
50
# File 'lib/applitools/core/eyes_base_configuration.rb', line 45

def merge(other_config)
  return if object_id == other_config.object_id
  (config_keys + other_config. config_keys).uniq do |k|
    merge_key(other_config, k)
  end
end

#merge_key(other_config, key) ⇒ Object



52
53
54
55
56
# File 'lib/applitools/core/eyes_base_configuration.rb', line 52

def merge_key(other_config, key)
  return unless other_config.send("defined_#{key}?")
  return unless respond_to?("#{key}=")
  send("#{key}=", other_config.send(key))
end

#scroll_root_elementObject



256
257
258
# File 'lib/applitools/core/eyes_base_configuration.rb', line 256

def scroll_root_element
  config_hash[:scroll_root_element]
end

#scroll_root_element=(value) ⇒ Object

scrollRootElement?: TElement | TSelector



253
254
255
# File 'lib/applitools/core/eyes_base_configuration.rb', line 253

def scroll_root_element=(value)
  config_hash[:scroll_root_element] = value
end

#set_aut_proxy(uri, user = nil, password = nil, mode = nil, domains = nil) ⇒ Object



143
144
145
# File 'lib/applitools/core/eyes_base_configuration.rb', line 143

def set_aut_proxy(uri, user = nil, password = nil, mode = nil, domains = nil)
  self.aut_proxy = Applitools::Connectivity::AutProxy.new(uri, user, password, nil, mode, domains)
end

#set_proxy(uri, user = nil, password = nil) ⇒ Object



139
140
141
# File 'lib/applitools/core/eyes_base_configuration.rb', line 139

def set_proxy(uri, user = nil, password = nil)
  self.proxy = Applitools::Connectivity::Proxy.new(uri, user, password)
end

#short_descriptionObject



135
136
137
# File 'lib/applitools/core/eyes_base_configuration.rb', line 135

def short_description
  "#{test_name} of #{app_name}"
end

#to_sObject



62
63
64
65
66
# File 'lib/applitools/core/eyes_base_configuration.rb', line 62

def to_s
  config_keys.map do |k|
    "#{k} = #{send(k)}"
  end.join("\n")
end

#valid?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/applitools/core/eyes_base_configuration.rb', line 68

def valid?
  validation_errors.clear

  validation_errors[:app_name] = ':app_name is required' unless app_name
  validation_errors[:test_name] = ':test_name is required' unless test_name

  validation_errors[:app_name] = ':app_name is required' if app_name && app_name.empty?
  validation_errors[:test_name] = ':test_name is required' if test_name && test_name.empty?
  # validation_errors[:viewport_size] = ':viewport_size is required' if viewport_size.square.zero?
  return true if validation_errors.keys.size.zero?
  false
end