Class: Applitools::Selenium::EyesScreenshot

Inherits:
EyesScreenshot
  • Object
show all
Defined in:
lib/applitools/selenium/eyes_screenshot.rb

Direct Known Subclasses

FullpageScreenshot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, options = {}) ⇒ EyesScreenshot

Returns a new instance of EyesScreenshot.



9
10
11
12
13
14
15
16
17
18
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 9

def initialize(image, options = {})
  super image
  self.region_provider = options[:region_provider] if options[:region_provider]
  Applitools::ArgumentGuard.is_a?(
    region_provider,
    'options[:region_provider]',
    Applitools::Selenium::RegionProvider
  )
  self.driver = region_provider.driver
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



6
7
8
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 6

def driver
  @driver
end

#region_providerObject

Returns the value of attribute region_provider.



6
7
8
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 6

def region_provider
  @region_provider
end

Instance Method Details

#convert_location(location, _from, _to) ⇒ Object



20
21
22
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 20

def convert_location(location, _from, _to)
  location.offset_negative(top_left_location)
end

#intersected_region(region, original_coordinate_types, result_coordinate_types) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 44

def intersected_region(region, original_coordinate_types, result_coordinate_types)
  raise Applitools::Selenium::UnsupportedCoordinateType, original_coordinate_types unless
      original_coordinate_types == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
  raise Applitools::Selenium::UnsupportedCoordinateType, result_coordinate_types unless
      result_coordinate_types == Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]

  return Applitools::Region::EMPTY if region.empty?

  intersected_region = convert_region_location(
    region, original_coordinate_types, Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
  )

  intersected_region.intersect(image_region)
end

#location_in_screenshot(location, coordinate_type) ⇒ Applitools::Location

Returns the location in the screenshot.

Parameters:

  • location (Applitools::Location)

    The location.

  • coordinate_type (Applitools::EyesScreenshot::COORDINATE_TYPES)

    The type of the coordinate.

Returns:

  • (Applitools::Location)

    The location instance in the screenshot.

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/applitools/selenium/eyes_screenshot.rb', line 29

def location_in_screenshot(location, coordinate_type)
  raise Applitools::Selenium::UnsupportedCoordinateType, coordinate_type unless
      coordinate_type == Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]

  location = convert_location(
    location, coordinate_type, Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
  )

  unless image_region.contains?(location.x, location.y)
    raise Applitools::OutOfBoundsException,
      "Location #{location} (#{coordinate_type}) is not visible in screenshot!"
  end
  location
end