Class: Applitools::Appium::Eyes

Inherits:
Selenium::SeleniumEyes
  • Object
show all
Defined in:
lib/applitools/appium/eyes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.status_bar_height = 0
  self.utils = Applitools::Appium::Utils
end

Instance Attribute Details

#status_bar_heightObject

Returns the value of attribute status_bar_height.



4
5
6
# File 'lib/applitools/appium/eyes.rb', line 4

def status_bar_height
  @status_bar_height
end

Class Method Details

.environment_sdkObject



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

Raises:

  • (Applitools::EyesError)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/applitools/appium/eyes.rb', line 130

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

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

Examples:

Basic check with tag and target

eyes.check('Login page', Applitools::Appium::Target.window)

Check with tag and hash options

eyes.check('Login form', target: Applitools::Appium::Target.window.fully(false))

Check with target only

eyes.check(Applitools::Appium::Target.window)

Check with options hash

eyes.check(name: 'Login page', target: Applitools::Appium::Target.window)

Overloads:

  • #check(tag, target) ⇒ Applitools::MatchResult

    Parameters:

    • tag (String)

      A name to be associated with the check

    • target (Applitools::Selenium::Target, Applitools::Appium::Target)

      The target for the check

  • #check(tag, options) ⇒ Applitools::MatchResult

    Parameters:

    • tag (String)

      A name to be associated with the check

    • options (Hash)

      The options hash

    Options Hash (options):

  • #check(target) ⇒ Applitools::MatchResult

    Parameters:

  • #check(options) ⇒ Applitools::MatchResult

    Parameters:

    • options (Hash)

      The options hash

    Options Hash (options):

    • :name, (String)

      :tag A name to be associated with the check

    • :target (Applitools::Selenium::Target, Applitools::Appium::Target)

      The target for the check

Returns:

  • (Applitools::MatchResult)

    The match result

Raises:

  • (Applitools::EyesIllegalArgument)

    If the target is not a valid Target instance



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
# 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?

  universal_check(name, target)
end

#check_region(*args) ⇒ Object



124
125
126
127
128
# File 'lib/applitools/appium/eyes.rb', line 124

def check_region(*args)
  options = { timeout: USE_DEFAULT_MATCH_TIMEOUT, tag: nil }.merge! Applitools::Utils.extract_options!(args)
  target = Applitools::Appium::Target.new.region(*args).timeout(options[:match_timeout])
  check(options[:tag], target)
end

#check_window(tag = nil, match_timeout = USE_DEFAULT_MATCH_TIMEOUT) ⇒ Object



117
118
119
120
121
122
# File 'lib/applitools/appium/eyes.rb', line 117

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_dataObject



113
114
115
# File 'lib/applitools/appium/eyes.rb', line 113

def dom_data
  {}
end

#use_system_screenshot(value = true) ⇒ Object



157
158
159
160
# File 'lib/applitools/appium/eyes.rb', line 157

def use_system_screenshot(value = true)
  self.screenshot_mode = !value ? 'applitools-lib' : 'default'
  self
end