Class: Applitools::EyesBase
- Inherits:
-
Object
- Object
- Applitools::EyesBase
- Extended by:
- Helpers, Forwardable
- Includes:
- MatchLevelSetter
- Defined in:
- lib/applitools/core/eyes_base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: UserInputArray
Constant Summary collapse
- DEFAULT_MATCH_TIMEOUT =
seconds
2
- USE_DEFAULT_TIMEOUT =
-1
- SCREENSHOT_AS_IS =
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is].freeze
- CONTEXT_RELATIVE =
Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative].freeze
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
Returns the value of attribute agent_id.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#compare_with_parent_branch ⇒ Object
Returns the value of attribute compare_with_parent_branch.
-
#cut_provider ⇒ Object
Returns the value of attribute cut_provider.
-
#default_match_settings ⇒ Object
Returns the value of attribute default_match_settings.
-
#exact ⇒ Object
Returns the value of attribute exact.
-
#failure_reports ⇒ Object
Returns the value of attribute failure_reports.
-
#host_app ⇒ Object
Returns the value of attribute host_app.
-
#host_os ⇒ Object
Returns the value of attribute host_os.
-
#inferred_environment ⇒ Object
Returns the value of attribute inferred_environment.
-
#match_level ⇒ Object
Returns the value of attribute match_level.
-
#match_timeout ⇒ Object
Returns the value of attribute match_timeout.
-
#position_provider ⇒ Object
Returns the value of attribute position_provider.
-
#remove_session_if_matching ⇒ Object
Returns the value of attribute remove_session_if_matching.
-
#save_failed_tests ⇒ Object
Returns the value of attribute save_failed_tests.
-
#save_new_tests ⇒ Object
Returns the value of attribute save_new_tests.
-
#scale_ratio ⇒ Object
Returns the value of attribute scale_ratio.
-
#server_remainder ⇒ Object
Returns the value of attribute server_remainder.
-
#server_scale ⇒ Object
Returns the value of attribute server_scale.
-
#verbose_results ⇒ boolean
If set to true it will display test results in verbose format, including all fields returned by the server Default value is false.
-
#viewport_size ⇒ Object
Returns the value of attribute viewport_size.
Instance Method Summary collapse
- #abort_if_not_closed ⇒ Object
- #add_property(name, value) ⇒ Object
- #check_single_base(region_provider, retry_timeout, match_window_data) ⇒ Object
- #check_window_base(region_provider, retry_timeout, match_window_data) ⇒ Object
-
#close(throw_exception = true, be_silent = false) ⇒ Object
Closes eyes otherwise the test will pass.
- #disabled=(value) ⇒ Object
- #disabled? ⇒ Boolean
- #ensure_running_session ⇒ Object
-
#initialize(server_url = nil) ⇒ EyesBase
constructor
A new instance of EyesBase.
- #new_session? ⇒ Boolean
- #open? ⇒ Boolean
- #open_base(options) ⇒ Object
- #running_session? ⇒ Boolean
-
#set_default_match_settings(value, exact_options = {}) ⇒ Target
Sets default match_level which will be applied to any test, unless match_level is set for a test explicitly.
Methods included from Helpers
abstract_attr_accessor, abstract_method, environment_attribute, environment_variables
Methods included from MatchLevelSetter
Constructor Details
#initialize(server_url = nil) ⇒ EyesBase
Returns a new instance of EyesBase.
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 86 87 |
# File 'lib/applitools/core/eyes_base.rb', line 55 def initialize(server_url = nil) self.server_connector = Applitools::Connectivity::ServerConnector.new(server_url) self.disabled = false @viewport_size = nil self.match_timeout = DEFAULT_MATCH_TIMEOUT self.running_session = nil self.save_new_tests = true self.save_failed_tests = false self.remove_session_if_matching = false self.agent_id = nil self.last_screenshot = nil @user_inputs = UserInputArray.new self.app_output_provider = Object.new self.verbose_results = false self.failed = false @inferred_environment = nil @properties = [] @server_scale = 0 @server_remainder = 0 get_app_output_method = ->(r, s) { get_app_output_with_screenshot r, s } app_output_provider.instance_eval do define_singleton_method :app_output do |r, s| get_app_output_method.call(r, s) end end self.exact = nil self.match_level = Applitools::MATCH_LEVEL[:strict] self.server_scale = 0 self.server_remainder = 0 self.compare_with_parent_branch = false end |
Instance Attribute Details
#agent_id ⇒ Object
Returns the value of attribute agent_id.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def agent_id @agent_id end |
#app_name ⇒ Object
Returns the value of attribute app_name.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def app_name @app_name end |
#batch ⇒ Object
Returns the value of attribute batch.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def batch @batch end |
#compare_with_parent_branch ⇒ Object
Returns the value of attribute compare_with_parent_branch.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def compare_with_parent_branch @compare_with_parent_branch end |
#cut_provider ⇒ Object
Returns the value of attribute cut_provider.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def cut_provider @cut_provider end |
#default_match_settings ⇒ Object
Returns the value of attribute default_match_settings.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def default_match_settings @default_match_settings end |
#exact ⇒ Object
Returns the value of attribute exact.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def exact @exact end |
#failure_reports ⇒ Object
Returns the value of attribute failure_reports.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def failure_reports @failure_reports end |
#host_app ⇒ Object
Returns the value of attribute host_app.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def host_app @host_app end |
#host_os ⇒ Object
Returns the value of attribute host_os.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def host_os @host_os end |
#inferred_environment ⇒ Object
Returns the value of attribute inferred_environment.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def inferred_environment @inferred_environment end |
#match_level ⇒ Object
Returns the value of attribute match_level.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def match_level @match_level end |
#match_timeout ⇒ Object
Returns the value of attribute match_timeout.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def match_timeout @match_timeout end |
#position_provider ⇒ Object
Returns the value of attribute position_provider.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def position_provider @position_provider end |
#remove_session_if_matching ⇒ Object
Returns the value of attribute remove_session_if_matching.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def remove_session_if_matching @remove_session_if_matching end |
#save_failed_tests ⇒ Object
Returns the value of attribute save_failed_tests.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def save_failed_tests @save_failed_tests end |
#save_new_tests ⇒ Object
Returns the value of attribute save_new_tests.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def save_new_tests @save_new_tests end |
#scale_ratio ⇒ Object
Returns the value of attribute scale_ratio.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def scale_ratio @scale_ratio end |
#server_remainder ⇒ Object
Returns the value of attribute server_remainder.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def server_remainder @server_remainder end |
#server_scale ⇒ Object
Returns the value of attribute server_scale.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def server_scale @server_scale end |
#verbose_results ⇒ boolean
If set to true it will display test results in verbose format, including all fields returned by the server Default value is false.
39 40 41 42 43 |
# File 'lib/applitools/core/eyes_base.rb', line 39 attr_accessor :app_name, :batch, :agent_id, :full_agent_id, :match_timeout, :save_new_tests, :save_failed_tests, :failure_reports, :default_match_settings, :cut_provider, :scale_ratio, :host_os, :host_app, :position_provider, :viewport_size, :verbose_results, :inferred_environment, :remove_session_if_matching, :server_scale, :server_remainder, :match_level, :exact, :compare_with_parent_branch |
#viewport_size ⇒ Object
Returns the value of attribute viewport_size.
39 40 41 |
# File 'lib/applitools/core/eyes_base.rb', line 39 def @viewport_size end |
Instance Method Details
#abort_if_not_closed ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/applitools/core/eyes_base.rb', line 184 def abort_if_not_closed if disabled? logger.info "#{__method__} Ignored" return false end self.open = false self.last_screenshot = nil clear_user_inputs if running_session.nil? logger.info 'Closed' return false end logger.info 'Aborting server session...' server_connector.stop_session(running_session, true, false) logger.info '---Test aborted' rescue Applitools::EyesError => e logger.error e. ensure self.running_session = nil end |
#add_property(name, value) ⇒ Object
180 181 182 |
# File 'lib/applitools/core/eyes_base.rb', line 180 def add_property(name, value) @properties << { name: name, value: value } end |
#check_single_base(region_provider, retry_timeout, match_window_data) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/applitools/core/eyes_base.rb', line 322 def check_single_base(region_provider, retry_timeout, match_window_data) if disabled? logger.info "#{__method__} Ignored" result = Applitools::MatchResults.new result.as_expected = true return result end raise Applitools::EyesError.new 'Eyes not open' unless open? Applitools::ArgumentGuard.not_nil region_provider, 'region_provider' logger.info( "check_single_base(#{region_provider}, #{match_window_data.tag}, #{match_window_data.ignore_mismatch}," \ " #{retry_timeout})" ) tag = '' if tag.nil? session_start_info = SessionStartInfo.new agent_id: base_agent_id, app_id_or_name: app_name, scenario_id_or_name: test_name, batch_info: batch, env_name: baseline_env_name, environment: app_environment, default_match_settings: default_match_settings, branch_name: branch_name, parent_branch_name: parent_branch_name, properties: properties match_window_data.start_info = session_start_info match_window_data.update_baseline_if_new = save_new_tests match_window_data.update_baseline_if_different = save_failed_tests match_window_data.remove_session_if_matching = remove_session_if_matching match_window_data.scale = server_scale match_window_data.remainder = server_remainder match_window_task = Applitools::MatchSingleTask.new( logger, match_timeout, app_output_provider, server_connector ) logger.info 'Calling match_window...' result = match_window_task.match_window( match_window_data, last_screenshot: last_screenshot, region_provider: region_provider, should_match_window_run_once_on_timeout: should_match_window_run_once_on_timeout, retry_timeout: retry_timeout ) do |match_results| results = match_results.original_results not_aborted = !results['isAborted'] new_and_saved = results['isNew'] && save_new_tests different_and_saved = results['isDifferent'] && save_failed_tests not_a_mismatch = !results['isDifferent'] && !results['isNew'] not_aborted && (new_and_saved || different_and_saved || not_a_mismatch) end logger.info 'match_window done!' if result.as_expected? clear_user_inputs self.last_screenshot = result.screenshot else unless match_window_data.ignore_mismatch clear_user_inputs self.last_screenshot = result.screenshot end self.should_match_window_run_once_on_timeout = true logger.info "Mistmatch! #{tag}" if failure_reports == :immediate raise Applitools::TestFailedException.new "Mistmatch found in #{session_start_info.scenario_id_or_name}" \ " of #{session_start_info.app_id_or_name}" end end logger.info 'Done!' result.original_results end |
#check_window_base(region_provider, retry_timeout, match_window_data) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/applitools/core/eyes_base.rb', line 267 def check_window_base(region_provider, retry_timeout, match_window_data) if disabled? logger.info "#{__method__} Ignored" result = Applitools::MatchResults.new result.as_expected = true return result end raise Applitools::EyesError.new 'Eyes not open' unless open? Applitools::ArgumentGuard.not_nil region_provider, 'region_provider' logger.info( "check_window_base(#{region_provider}, #{match_window_data.tag}, #{match_window_data.ignore_mismatch}," \ " #{retry_timeout})" ) tag = '' if tag.nil? ensure_running_session match_window_data.user_inputs = user_inputs logger.info 'Calling match_window...' result = @match_window_task.match_window( match_window_data, last_screenshot: last_screenshot, region_provider: region_provider, should_match_window_run_once_on_timeout: should_match_window_run_once_on_timeout, retry_timeout: retry_timeout ) logger.info 'match_window done!' if result.as_expected? clear_user_inputs self.last_screenshot = result.screenshot else unless match_window_data.ignore_mismatch clear_user_inputs self.last_screenshot = result.screenshot end self.should_match_window_run_once_on_timeout = true self.failed = true logger.info "Mistmatch! #{tag}" unless running_session.new_session? if failure_reports == :immediate raise Applitools::TestFailedException.new "Mistmatch found in #{session_start_info.scenario_id_or_name}" \ " of #{session_start_info.app_id_or_name}" end end logger.info 'Done!' result end |
#close(throw_exception = true, be_silent = false) ⇒ Object
Closes eyes otherwise the test will pass. Default is true
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/applitools/core/eyes_base.rb', line 405 def close(throw_exception = true, be_silent = false) if disabled? logger.info "#{__method__} Ignored" return false end logger.info "close(#{throw_exception})" raise Applitools::EyesError.new 'Eyes not open' unless open? self.open = false self.last_screenshot = nil clear_user_inputs unless running_session be_silent || logger.info('Server session was not started') be_silent || logger.info('--- Empty test ended') return Applitools::TestResults.new end is_new_session = running_session.new_session? session_results_url = running_session.url logger.info 'Ending server session...' save = is_new_session && save_new_tests || !is_new_session && failed && save_failed_tests logger.info "Automatically save test? #{save}" results = server_connector.stop_session running_session, false, save results.is_new = is_new_session results.url = session_results_url logger.info results.to_s(verbose_results) if results.unresolved? if results.new? logger.error "--- New test ended. see details at #{session_results_url}" = "New test '#{session_start_info.scenario_id_or_name}' " \ "of '#{session_start_info.app_id_or_name}' " \ "Please approve the baseline at #{session_results_url} " raise Applitools::NewTestError.new , results if throw_exception else logger.error "--- Differences are found. see details at #{session_results_url}" = "Test '#{session_start_info.scenario_id_or_name}' " \ "of '#{session_start_info.app_id_or_name}' " \ "detected differences! See details at #{session_results_url}" raise Applitools::DiffsFoundError.new , results if throw_exception end return results end if results.failed? logger.error "--- Failed test ended. see details at #{session_results_url}" = "Test '#{session_start_info.scenario_id_or_name}' of '#{session_start_info.app_id_or_name}' " \ "is failed! See details at #{session_results_url}" raise Applitools::TestFailedError.new , results if throw_exception return results end logger.info '--- Test passed' return results ensure self.running_session = nil self.current_app_name = nil end |
#disabled=(value) ⇒ Object
156 157 158 |
# File 'lib/applitools/core/eyes_base.rb', line 156 def disabled=(value) @disabled = Applitools::Utils.boolean_value value end |
#disabled? ⇒ Boolean
160 161 162 |
# File 'lib/applitools/core/eyes_base.rb', line 160 def disabled? @disabled end |
#ensure_running_session ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/applitools/core/eyes_base.rb', line 252 def ensure_running_session return if running_session logger.info 'No running session, calling start session..' start_session logger.info 'Done!' @match_window_task = Applitools::MatchWindowTask.new( logger, running_session, match_timeout, app_output_provider, server_connector ) end |
#new_session? ⇒ Boolean
172 173 174 |
# File 'lib/applitools/core/eyes_base.rb', line 172 def new_session? running_session && running_session.new_session? end |
#open? ⇒ Boolean
164 165 166 |
# File 'lib/applitools/core/eyes_base.rb', line 164 def open? @open end |
#open_base(options) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/applitools/core/eyes_base.rb', line 210 def open_base() if disabled? logger.info "#{__method__} Ignored" return false end if open? abort_if_not_closed raise Applitools::EyesError.new 'A test is already running' end Applitools::ArgumentGuard.hash , 'open_base parameter', [:test_name] = { session_type: 'SEQUENTIAL' } = .merge if app_name.nil? Applitools::ArgumentGuard.not_nil [:app_name], 'options[:app_name]' self.current_app_name = [:app_name] else self.current_app_name = app_name end Applitools::ArgumentGuard.not_nil [:test_name], 'options[:test_name]' self.test_name = [:test_name] logger.info "Agent = #{full_agent_id}" logger.info "openBase(app_name: #{[:app_name]}, test_name: #{[:test_name]}," \ " viewport_size: #{[:viewport_size]})" raise Applitools::EyesError.new 'API key is missing! Please set it using api_key=' if api_key.nil? || (api_key && api_key.empty?) self. = [:viewport_size] self.session_type = [:session_type] yield if block_given? self.open = true rescue Applitools::EyesError => e logger.error e. raise e end |
#running_session? ⇒ Boolean
168 169 170 |
# File 'lib/applitools/core/eyes_base.rb', line 168 def running_session? running_session.nil? ? false : true end |
#set_default_match_settings(value, exact_options = {}) ⇒ Target
Sets default match_level which will be applied to any test, unless match_level is set for a test explicitly
104 105 106 |
# File 'lib/applitools/core/eyes_base.rb', line 104 def set_default_match_settings(value, = {}) (self.match_level, self.exact) = match_level_with_exact(value, ) end |