Class: Applitools::Appium::Eyes
- Inherits:
-
Selenium::SeleniumEyes
- Object
- Selenium::SeleniumEyes
- Applitools::Appium::Eyes
- Defined in:
- lib/applitools/appium/eyes.rb
Instance Attribute Summary collapse
-
#status_bar_height ⇒ Object
Returns the value of attribute status_bar_height.
Class Method Summary collapse
- .environment_sdk ⇒ Object
- .set_mobile_capabilities(caps, api_key = nil, server_url = nil, proxy = nil) ⇒ Object (also: set_nmg_capabilities)
Instance Method Summary collapse
- #capture_screenshot ⇒ Object
-
#check(*args) ⇒ Applitools::MatchResult
Verifies a target in the application window.
- #check_native(name, target) ⇒ Object
- #check_region(*args) ⇒ Object
- #check_window(tag = nil, match_timeout = USE_DEFAULT_MATCH_TIMEOUT) ⇒ Object
- #dom_data ⇒ Object
- #get_app_output_with_screenshot(*args) ⇒ Object
-
#initialize(*args) ⇒ Eyes
constructor
A new instance of Eyes.
- #native_app? ⇒ Boolean
- #use_system_screenshot(value = true) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Eyes
Returns a new instance of Eyes.
11 12 13 14 15 16 17 18 |
# File 'lib/applitools/appium/eyes.rb', line 11 def initialize(*args) super self.dont_get_title = true self.runner = Applitools::ClassicRunner.new unless runner self.base_agent_id = "eyes.appium.ruby/#{Applitools::EyesAppium::VERSION}".freeze self. = 0 self.utils = Applitools::Appium::Utils end |
Instance Attribute Details
#status_bar_height ⇒ Object
Returns the value of attribute status_bar_height.
4 5 6 |
# File 'lib/applitools/appium/eyes.rb', line 4 def @status_bar_height end |
Class Method Details
.environment_sdk ⇒ Object
20 21 22 23 24 25 |
# File 'lib/applitools/appium/eyes.rb', line 20 def self.environment_sdk { name: :eyes_appium, currentVersion: Applitools::EyesAppium::VERSION } end |
.set_mobile_capabilities(caps, api_key = nil, server_url = nil, proxy = nil) ⇒ Object Also known as: set_nmg_capabilities
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/applitools/appium/eyes.rb', line 192 def self.set_mobile_capabilities(caps, api_key = nil, server_url = nil, proxy = nil) api_key ||= ENV['APPLITOOLS_API_KEY'] raise Applitools::EyesError.new('No API key was given, or is an empty string.') if api_key.to_s.empty? server_url ||= ENV['APPLITOOLS_SERVER_URL'] proxy ||= ENV['APPLITOOLS_HTTP_PROXY'] new_caps = { APPLITOOLS_API_KEY: api_key, APPLITOOLS_SERVER_URL: server_url, APPLITOOLS_PROXY_URL: proxy }.compact # Removes nil values # Ensure `caps` is a hash to avoid NoMethodError for []= on nil caps ||= {} caps[:optionalIntentArguments] = "--es APPLITOOLS '#{new_caps.to_json}'" caps[:processArguments] = { args: [], env: new_caps.merge(DYLD_INSERT_LIBRARIES: "@executable_path/Frameworks/UFG_lib.xcframework/ios-arm64/UFG_lib.framework/UFG_lib:@executable_path/Frameworks/UFG_lib.xcframework/ios-arm64_x86_64-simulator/UFG_lib.framework/UFG_lib") } end |
Instance Method Details
#capture_screenshot ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/applitools/appium/eyes.rb', line 141 def capture_screenshot logger.info 'Getting screenshot (capture_screenshot() has been invoked)' case eyes_element_to_check when Applitools::Region when Selenium::WebDriver::Element, Applitools::Selenium::Element element_screenshot end end |
#check(tag, target) ⇒ Applitools::MatchResult #check(tag, options) ⇒ Applitools::MatchResult #check(target) ⇒ Applitools::MatchResult #check(options) ⇒ Applitools::MatchResult
Verifies a target in the application window.
This method performs a visual check using Applitools AI. It can be called in multiple ways supporting different argument patterns for flexibility.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/applitools/appium/eyes.rb', line 65 def check(*args) args.compact! # Extract name and target based on argument types name = nil target = nil # Handle first argument case args.first when String # Format: check('name', target_object) # Format: check('name', target: target_object) name = args.shift # Check if next argument is a hash with :target key if args.first.is_a?(Hash) && args.first.key?(:target) hash_arg = args.shift target = hash_arg[:target] else # Otherwise it should be a direct target object target = args.shift end when Applitools::Selenium::Target, Applitools::Appium::Target # Format: check(target_object) target = args.shift when Hash # Format: check(name: 'name', target: target_object) hash_arg = args.shift name = hash_arg[:name] || hash_arg[:tag] target = hash_arg[:target] end logger.info "check(#{name}) is called" self.tag_for_debug = name # Extract the target object from its container if needed if target.is_a?(Hash) && target.key?(:target) target = target[:target] end # Ensure we have a proper Target object Applitools::ArgumentGuard.one_of? target, 'target', [Applitools::Selenium::Target, Applitools::Appium::Target] # target.fully(false) if target.options[:stitch_content].nil? return universal_check(name, target) return check_native(name, target) if native_app? super end |
#check_native(name, target) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/applitools/appium/eyes.rb', line 118 def check_native(name, target) logger.info "check_native(#{name}) is called" update_scaling_params target_to_check = target.finalize match_data = Applitools::MatchWindowData.new(default_match_settings) match_data.tag = name timeout = target_to_check.[:timeout] || USE_DEFAULT_MATCH_TIMEOUT eyes_element = target_to_check.region_to_check.call(driver) self.eyes_element_to_check = eyes_element region_provider = region_provider_class.new(driver, eyes_element) match_data.read_target(target_to_check, driver) check_window_base( region_provider, timeout, match_data ) end |
#check_region(*args) ⇒ Object
186 187 188 189 190 |
# File 'lib/applitools/appium/eyes.rb', line 186 def check_region(*args) = { timeout: USE_DEFAULT_MATCH_TIMEOUT, tag: nil }.merge! Applitools::Utils.(args) target = Applitools::Appium::Target.new.region(*args).timeout([:match_timeout]) check([:tag], target) end |
#check_window(tag = nil, match_timeout = USE_DEFAULT_MATCH_TIMEOUT) ⇒ Object
179 180 181 182 183 184 |
# File 'lib/applitools/appium/eyes.rb', line 179 def check_window(tag = nil, match_timeout = USE_DEFAULT_MATCH_TIMEOUT) target = Applitools::Appium::Target.window.tap do |t| t.timeout(match_timeout) end check(tag, target) end |
#dom_data ⇒ Object
175 176 177 |
# File 'lib/applitools/appium/eyes.rb', line 175 def dom_data {} end |
#get_app_output_with_screenshot(*args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/applitools/appium/eyes.rb', line 151 def get_app_output_with_screenshot(*args) result = super do |screenshot| if scale_provider scaled_image = scale_provider.scale_image(screenshot.image) self.screenshot = screenshot_class.new( Applitools::Screenshot.from_image( case scaled_image # when ChunkyPNG::Image # scaled_image when Applitools::Screenshot::Datastream scaled_image.image else raise Applitools::EyesError.new('Unknown image format after scale!') end ), status_bar_height: self.utils.(driver), device_pixel_ratio: self.utils.device_pixel_ratio(driver) ) end end self.screenshot_url = nil result end |
#native_app? ⇒ Boolean
136 137 138 139 |
# File 'lib/applitools/appium/eyes.rb', line 136 def native_app? return true if driver.current_context == 'NATIVE_APP' false end |
#use_system_screenshot(value = true) ⇒ Object
219 220 221 222 |
# File 'lib/applitools/appium/eyes.rb', line 219 def use_system_screenshot(value = true) self.screenshot_mode = !value ? 'applitools-lib' : 'default' self end |