class Applitools::Calabash::Eyes
Attributes
base_agent_id[RW]
context[R]
debug_screenshot_provider[RW]
debug_screenshots[RW]
device_pixel_ratio[RW]
full_page_capture_algorithm[RW]
tag_for_debug[RW]
title[RW]
Public Class Methods
new(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL)
click to toggle source
Calls superclass method
# File lib/applitools/calabash/eyes.rb, line 10 def initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) super self.runner = Applitools::ClassicRunner.new self.base_agent_id = "eyes.calabash.ruby/#{Applitools::VERSION}".freeze self.debug_screenshots = false self.debug_screenshot_provider = Applitools::DebugScreenshotProvider.new .tag_access { tag_for_debug } .debug_flag_access { debug_screenshots } end
Public Instance Methods
add_context(value)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 48 def add_context(value) @context = value end
capture_screenshot()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 56 def capture_screenshot return screenshot_provider.capture_screenshot(debug_suffix: tag_for_debug) unless full_page_capture_algorithm full_page_capture_algorithm.get_stitched_region end
check(*args)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 25 def check(*args) args.compact! case (first_arg = args.shift) when String name = first_arg target = args.shift when Applitools::Selenium::Target target = first_arg when Hash target = first_arg[:target] name = first_arg[:name] || first_arg[:tag] end self.tag_for_debug = get_tag_for_debug(name) check_it(name, target, Applitools::MatchWindowData.new(default_match_settings)) end
check_it(name, target, match_window_data)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 75 def check_it(name, target, match_window_data) Applitools::ArgumentGuard.not_nil(name, 'name') logger.info 'Full element requested' if target.options[:stitch_content] self.full_page_capture_algorithm = target.options[:stitch_content] && get_full_page_capture_algorithm(target.region_to_check) region_provider = if full_page_capture_algorithm entire_screenshot_region else get_region_provider(target) end match_window_data.tag = name match_window_data.read_target(target, nil) self.viewport_size = Applitools::Calabash::EyesSettings.instance.viewport_size if viewport_size.nil? if match_window_data.is_a? Applitools::MatchSingleCheckData return check_single_base( region_provider, target.options[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end check_window_base( region_provider, target.options[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end
entire_screenshot_region()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 123 def entire_screenshot_region Object.new.tap do |prov| prov.instance_eval do define_singleton_method :region do Applitools::Region::EMPTY end define_singleton_method :coordinate_type do nil end end end end
get_app_output_with_screenshot(*args)
click to toggle source
Calls superclass method
# File lib/applitools/calabash/eyes.rb, line 117 def get_app_output_with_screenshot(*args) result = super(*args, &:scale_it!) self.screenshot_url = nil result end
get_full_page_capture_algorithm(element)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 173 def get_full_page_capture_algorithm(element) logger.info "Trying to get full page capture algorithm for element #{element}..." environment = Applitools::Calabash::EnvironmentDetector.current_environment element_class = Applitools::Calabash::Utils.send("grub_#{environment}_class_name", context, element).first logger.info "Trying to get FullPageCaptureAlgorithm for #{element_class}..." algo = Applitools::Calabash::FullPageCaptureAlgorithm.get_algorithm_class(environment, element_class) if algo logger.info "Using #{algo}" algo = algo.new(screenshot_provider, element, debug_screenshot_provider: debug_screenshot_provider) else logger.info "FullPageCaptureAlgorithm for #{element_class} not found. Continue with :check_region instead" end algo end
get_region_provider(target)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 109 def get_region_provider(target) if (region_to_check = target.region_to_check).nil? entire_screenshot_region else region_for_element(region_to_check) end end
get_tag_for_debug(name)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 188 def get_tag_for_debug(name) return "#{app_name} #{test_name}" if name.empty? "#{app_name} #{test_name} - #{name}" end
inferred_environment()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 42 def inferred_environment return @inferred_environment unless @inferred_environment.nil? return unless device_pixel_ratio "device pixel ratio: #{device_pixel_ratio}" end
open(options = {})
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 20 def open(options = {}) Applitools::ArgumentGuard.hash options, 'open(options)', [:app_name, :test_name] open_base options end
region_for_element(region_to_check)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 137 def region_for_element(region_to_check) Object.new.tap do |prov| prov.instance_eval do define_singleton_method :region do case region_to_check when Applitools::Calabash::CalabashElement region_to_check.region when Applitools::Region region_to_check else raise Applitools::EyesError, "Incompatible region type: #{region_to_check.class}" end # region_to_check.respond_to?(:region) ? region_to_check.region : region_to_check end define_singleton_method :coordinate_type do Applitools::Calabash::EyesCalabashScreenshot::DRIVER end end end end
remove_context()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 52 def remove_context @context = nil end
screenshot_provider()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 61 def screenshot_provider env = Applitools::Calabash::EnvironmentDetector.current_environment case env when :android Applitools::Calabash::AndroidScreenshotProvider.instance.with_density(device_pixel_ratio) .using_context(context) .with_debug_screenshot_provider(debug_screenshot_provider) when :ios Applitools::Calabash::IosScreenshotProvider.instance.with_density(device_pixel_ratio) .using_context(context) .with_debug_screenshot_provider(debug_screenshot_provider) end end
vp_size()
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 158 def vp_size viewport_size end
Also aliased as: get_viewport_size
vp_size=(value, skip_check_if_open = false)
click to toggle source
# File lib/applitools/calabash/eyes.rb, line 162 def vp_size=(value, skip_check_if_open = false) unless skip_check_if_open || open? raise Applitools::EyesNotOpenException.new 'set_viewport_size: Eyes not open!' end Applitools::ArgumentGuard.not_nil 'value', value @viewport_size = Applitools::RectangleSize.for value end
Also aliased as: set_viewport_size