class Applitools::Selenium::EyesScreenshot

Attributes

driver[RW]
region_provider[RW]

Public Class Methods

new(image, options = {}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

convert_location(location, _from, _to) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Returns the location in the screenshot.

@param [Applitools::Location] location The location. @param [Applitools::EyesScreenshot::COORDINATE_TYPES] coordinate_type The type of the coordinate. @return [Applitools::Location] The location instance in the screenshot.

# 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