Class: Applitools::Calabash::Eyes
- Inherits:
-
EyesBase
- Object
- EyesBase
- Applitools::Calabash::Eyes
- Defined in:
- lib/applitools/calabash/eyes.rb
Instance Attribute Summary collapse
-
#base_agent_id ⇒ Object
Returns the value of attribute base_agent_id.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#debug_screenshot_provider ⇒ Object
Returns the value of attribute debug_screenshot_provider.
-
#debug_screenshots ⇒ Object
Returns the value of attribute debug_screenshots.
-
#device_pixel_ratio ⇒ Object
Returns the value of attribute device_pixel_ratio.
-
#full_page_capture_algorithm ⇒ Object
Returns the value of attribute full_page_capture_algorithm.
-
#tag_for_debug ⇒ Object
Returns the value of attribute tag_for_debug.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add_context(value) ⇒ Object
- #capture_screenshot ⇒ Object
- #check(*args) ⇒ Object
- #check_it(name, target, match_window_data) ⇒ Object
- #entire_screenshot_region ⇒ Object
- #get_app_output_with_screenshot(*args) ⇒ Object
- #get_full_page_capture_algorithm(element) ⇒ Object
- #get_region_provider(target) ⇒ Object
- #get_tag_for_debug(name) ⇒ Object
- #inferred_environment ⇒ Object
-
#initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) ⇒ Eyes
constructor
A new instance of Eyes.
- #open(options = {}) ⇒ Object
- #region_for_element(region_to_check) ⇒ Object
- #remove_context ⇒ Object
- #screenshot_provider ⇒ Object
- #vp_size ⇒ Object (also: #get_viewport_size)
- #vp_size=(value, skip_check_if_open = false) ⇒ Object (also: #set_viewport_size)
Constructor Details
#initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) ⇒ Eyes
Returns a new instance of Eyes.
10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#base_agent_id ⇒ Object
Returns the value of attribute base_agent_id.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def base_agent_id @base_agent_id end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/applitools/calabash/eyes.rb', line 8 def context @context end |
#debug_screenshot_provider ⇒ Object
Returns the value of attribute debug_screenshot_provider.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def debug_screenshot_provider @debug_screenshot_provider end |
#debug_screenshots ⇒ Object
Returns the value of attribute debug_screenshots.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def debug_screenshots @debug_screenshots end |
#device_pixel_ratio ⇒ Object
Returns the value of attribute device_pixel_ratio.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def device_pixel_ratio @device_pixel_ratio end |
#full_page_capture_algorithm ⇒ Object
Returns the value of attribute full_page_capture_algorithm.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def full_page_capture_algorithm @full_page_capture_algorithm end |
#tag_for_debug ⇒ Object
Returns the value of attribute tag_for_debug.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def tag_for_debug @tag_for_debug end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/applitools/calabash/eyes.rb', line 6 def title @title end |
Class Method Details
.environment_sdk ⇒ Object
20 21 22 23 24 25 |
# File 'lib/applitools/calabash/eyes.rb', line 20 def self.environment_sdk { name: :eyes_calabash, currentVersion: Applitools::EyesCalabash::VERSION } end |
Instance Method Details
#add_context(value) ⇒ Object
55 56 57 |
# File 'lib/applitools/calabash/eyes.rb', line 55 def add_context(value) @context = value end |
#capture_screenshot ⇒ Object
63 64 65 66 |
# File 'lib/applitools/calabash/eyes.rb', line 63 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/applitools/calabash/eyes.rb', line 32 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) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/applitools/calabash/eyes.rb', line 82 def check_it(name, target, match_window_data) Applitools::ArgumentGuard.not_nil(name, 'name') logger.info 'Full element requested' if target.[:stitch_content] self.full_page_capture_algorithm = target.[: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. = Applitools::Calabash::EyesSettings.instance. if .nil? if match_window_data.is_a? Applitools::MatchSingleCheckData return check_single_base( region_provider, target.[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end check_window_base( region_provider, target.[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end |
#entire_screenshot_region ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/applitools/calabash/eyes.rb', line 130 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) ⇒ Object
124 125 126 127 128 |
# File 'lib/applitools/calabash/eyes.rb', line 124 def get_app_output_with_screenshot(*args) result = super(*args, &:scale_it!) self.screenshot_url = nil result end |
#get_full_page_capture_algorithm(element) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/applitools/calabash/eyes.rb', line 180 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) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/applitools/calabash/eyes.rb', line 116 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) ⇒ Object
195 196 197 198 |
# File 'lib/applitools/calabash/eyes.rb', line 195 def get_tag_for_debug(name) return "#{app_name} #{test_name}" if name.empty? "#{app_name} #{test_name} - #{name}" end |
#inferred_environment ⇒ Object
49 50 51 52 53 |
# File 'lib/applitools/calabash/eyes.rb', line 49 def inferred_environment return @inferred_environment unless @inferred_environment.nil? return unless device_pixel_ratio "device pixel ratio: #{device_pixel_ratio}" end |
#open(options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/applitools/calabash/eyes.rb', line 27 def open( = {}) Applitools::ArgumentGuard.hash , 'open(options)', [:app_name, :test_name] open_base end |
#region_for_element(region_to_check) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/applitools/calabash/eyes.rb', line 144 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 ⇒ Object
59 60 61 |
# File 'lib/applitools/calabash/eyes.rb', line 59 def remove_context @context = nil end |
#screenshot_provider ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/applitools/calabash/eyes.rb', line 68 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 ⇒ Object Also known as: get_viewport_size
165 166 167 |
# File 'lib/applitools/calabash/eyes.rb', line 165 def vp_size end |
#vp_size=(value, skip_check_if_open = false) ⇒ Object Also known as: set_viewport_size
169 170 171 172 173 174 175 |
# File 'lib/applitools/calabash/eyes.rb', line 169 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 |