Class: Applitools::Calabash::EyesCalabashAndroidScreenshot

Inherits:
EyesCalabashScreenshot show all
Extended by:
Forwardable
Defined in:
lib/applitools/calabash/eyes_calabash_android_screenshot.rb

Defined Under Namespace

Classes: UnknownDeviceDensity

Constant Summary collapse

ANDROID_DENSITY =
{
  120 => 0.75,
  160 => 1,
  213 => 1.33,
  240 => 1.5,
  320 => 2,
  480 => 3,
  560 => 3.5,
  640 => 4
}.freeze
DENSITY_DEFAULT =
160

Constants inherited from EyesCalabashScreenshot

Applitools::Calabash::EyesCalabashScreenshot::CONTEXT_RELATIVE, Applitools::Calabash::EyesCalabashScreenshot::DRIVER, Applitools::Calabash::EyesCalabashScreenshot::SCREENSHOT_AS_IS

Constants inherited from EyesScreenshot

EyesScreenshot::COORDINATE_TYPES

Instance Attribute Summary

Attributes inherited from EyesCalabashScreenshot

#scale_factor

Attributes inherited from EyesScreenshot

#image, #top_left_location

Instance Method Summary collapse

Methods inherited from EyesCalabashScreenshot

#convert_location, #intersected_region, #location_in_screenshot, #scale_it!, #sub_screenshot

Methods inherited from EyesScreenshot

#sub_screenshots

Methods included from Helpers

#abstract_attr_accessor, #abstract_method, #env_variable, #environment_attribute, environment_variables

Constructor Details

#initialize(*args) ⇒ EyesCalabashAndroidScreenshot

Returns a new instance of EyesCalabashAndroidScreenshot.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/applitools/calabash/eyes_calabash_android_screenshot.rb', line 25

def initialize(*args)
  options = if args.last.is_a? Hash
              args.pop
            else
              {}
            end
  super(*args)
  @scale_factor = nil
  self.density = options[:density] if options[:density]
  @scale_factor ||= options[:scale_factor]
  @scale_factor = 1 unless @scale_factor
end

Instance Method Details

#convert_region_location(region, from, to) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/applitools/calabash/eyes_calabash_android_screenshot.rb', line 38

def convert_region_location(region, from, to)
  case from
  when DRIVER
    case to
    when SCREENSHOT_AS_IS
      region
    else
      raise Applitools::EyesError, "from: #{from}, to: #{to}"
    end
  when CONTEXT_RELATIVE
    case to
    when SCREENSHOT_AS_IS
      region.scale_it!(1.to_f / scale_factor) # !!!!!!
      region
    else
      raise Applitools::EyesError, "from: #{from}, to: #{to}"
    end
  else
    raise Applitools::EyesError, "from: #{from}, to: #{to}"
  end
  region
end

#density=(value) ⇒ Object



61
62
63
64
65
# File 'lib/applitools/calabash/eyes_calabash_android_screenshot.rb', line 61

def density=(value)
  logger.warn("Trying to set unknown device density - #{value}") unless
      ANDROID_DENSITY.keys.include?(value.to_i)
  @scale_factor = value.to_f / DENSITY_DEFAULT
end