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
}.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 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.



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

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

Class Method Details

.default_configObject



25
26
27
# File 'lib/applitools/core/eyes_base_configuration.rb', line 25

def default_config
  DEFAULT_CONFIG
end

Instance Method Details

#batchObject



71
72
73
74
75
76
77
# File 'lib/applitools/core/eyes_base_configuration.rb', line 71

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

#batch=(value) ⇒ Object



79
80
81
# File 'lib/applitools/core/eyes_base_configuration.rb', line 79

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

#config_keysObject



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

def config_keys
  config_hash.keys
end

#default_match_settingsObject



145
146
147
148
149
150
151
152
# File 'lib/applitools/core/eyes_base_configuration.rb', line 145

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

#default_match_settings=(value) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/applitools/core/eyes_base_configuration.rb', line 130

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)


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

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



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

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

#merge(other_config) ⇒ Object



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

def merge(other_config)
  return if self.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



42
43
44
45
46
# File 'lib/applitools/core/eyes_base_configuration.rb', line 42

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

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



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

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



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

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

#short_descriptionObject



112
113
114
# File 'lib/applitools/core/eyes_base_configuration.rb', line 112

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

#to_sObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/applitools/core/eyes_base_configuration.rb', line 58

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