Class: Applitools::Appium::Eyes

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Eyes

Returns a new instance of Eyes.



11
12
13
14
15
16
17
# File 'lib/applitools/appium/eyes.rb', line 11

def initialize(*args)
  super
  self.dont_get_title = true
  self.runner = Applitools::ClassicRunner.new
  self.base_agent_id = "eyes.appium.ruby/#{Applitools::VERSION}".freeze
  self.status_bar_height = 0
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

Instance Method Details

#capture_screenshotObject



68
69
70
71
72
73
74
75
76
# File 'lib/applitools/appium/eyes.rb', line 68

def capture_screenshot
  logger.info 'Getting screenshot (capture_screenshot() has been invoked)'
  case eyes_element_to_check
  when Applitools::Region
    viewport_screenshot
  when Selenium::WebDriver::Element, Applitools::Selenium::Element
    element_screenshot
  end
end

#check(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/applitools/appium/eyes.rb', line 21

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

  logger.info "check(#{name}) is called"
  self.tag_for_debug = name
  Applitools::ArgumentGuard.one_of? target, 'target', [Applitools::Selenium::Target, Applitools::Appium::Target]

  return check_native(name, target) if native_app?
  super
end

#check_native(name, target) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/applitools/appium/eyes.rb', line 45

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.options[: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



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

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



106
107
108
109
110
111
# File 'lib/applitools/appium/eyes.rb', line 106

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



102
103
104
# File 'lib/applitools/appium/eyes.rb', line 102

def dom_data
  {}
end

#get_app_output_with_screenshot(*args) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/applitools/appium/eyes.rb', line 78

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: Applitools::Utils::EyesSeleniumUtils.status_bar_height(driver),
        device_pixel_ratio: Applitools::Utils::EyesSeleniumUtils.device_pixel_ratio(driver)
      )
    end
  end
  self.screenshot_url = nil
  result
end

#native_app?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/applitools/appium/eyes.rb', line 63

def native_app?
  return true if driver.current_context == 'NATIVE_APP'
  false
end