Class: Applitools::EyesBaseConfiguration

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

Constant Summary collapse

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'] || 'https://eyessdk.applitools.com',
  api_key: ENV['APPLITOOLS_API_KEY'] || ENV['bamboo_APPLITOOLS_API_KEY'] || '',
  match_level: Applitools::MatchLevel::STRICT,
  scale: 0,
  remainder: 0,
  save_new_tests: true
}.freeze

Instance Attribute Summary

Attributes inherited from AbstractConfiguration

#config_hash, #validation_errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MatchLevelSetter

#match_level_with_exact

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.



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

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

Class Method Details

.default_configObject



29
30
31
# File 'lib/applitools/core/eyes_base_configuration.rb', line 29

def default_config
  DEFAULT_CONFIG
end

Instance Method Details

#batchObject



75
76
77
78
79
80
81
# File 'lib/applitools/core/eyes_base_configuration.rb', line 75

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

#batch=(value) ⇒ Object



83
84
85
# File 'lib/applitools/core/eyes_base_configuration.rb', line 83

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

#config_keysObject



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

def config_keys
  config_hash.keys
end

#default_match_settingsObject



150
151
152
153
154
155
156
157
# File 'lib/applitools/core/eyes_base_configuration.rb', line 150

def default_match_settings
  {
    match_level: match_level,
    exact: exact,
    scale: scale,
    remainder: remainder
  }
end

#default_match_settings=(value) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/applitools/core/eyes_base_configuration.rb', line 135

def default_match_settings=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Hash
  extra_keys = value.keys - match_level_keys
  unless extra_keys.empty?
    raise Applitools::EyesIllegalArgument.new(
      "Pasiing extra keys is prohibited! Passed extra keys: #{extra_keys}"
    )
  end
  result = default_match_settings.merge!(value)
  (self.match_level, self.exact) = match_level_with_exact(result[:match_level], result[:exact])
  self.scale = result[:scale]
  self.remainder = result[:remainder]
  result
end

#match_level=(value) ⇒ Object

Raises:

  • (Applitools::EyesError)


124
125
126
127
128
129
# File 'lib/applitools/core/eyes_base_configuration.rb', line 124

def match_level=(value)
  return config_hash[:match_level] = value if Applitools::MatchLevel.enum_values.include?(value)
  return config_hash[:match_level] = Applitools::MATCH_LEVEL[value.to_sym] if
      Applitools::MATCH_LEVEL.keys.include?(value.to_sym)
  raise Applitools::EyesError, "Unknown match level #{value}"
end

#match_level_keysObject



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

def match_level_keys
  %w(match_level exact scale remainder).map(&:to_sym)
end

#merge(other_config) ⇒ Object



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

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



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

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

#set_default_match_settings(value, exact_options = {}) ⇒ Object



131
132
133
# File 'lib/applitools/core/eyes_base_configuration.rb', line 131

def set_default_match_settings(value, exact_options = {})
  (self.match_level, self.exact) = match_level_with_exact(value, exact_options)
end

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



120
121
122
# File 'lib/applitools/core/eyes_base_configuration.rb', line 120

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

#short_descriptionObject



116
117
118
# File 'lib/applitools/core/eyes_base_configuration.rb', line 116

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

#to_sObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/applitools/core/eyes_base_configuration.rb', line 62

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