Class: Applitools::Selenium::CssTranslatePositionProvider

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/selenium/css_translate_position_provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executor, disable_horizontal = false, disable_vertical = false, max_width = nil, max_height = nil) ⇒ CssTranslatePositionProvider

Initialize a class instance.

Parameters:

  • executor (Applitools::Selenium::Driver)

    The driver instance.

  • disable_horizontal (Boolean) (defaults to: false)

    Whether to disable horizontal movement or not.

  • disable_vertical (Boolean) (defaults to: false)

    Whether to disable vertical movement or not.

  • max_width (Integer) (defaults to: nil)

    The max width.

  • max_height (Integer) (defaults to: nil)

    The max height.



16
17
18
19
20
21
22
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 16

def initialize(executor, disable_horizontal = false, disable_vertical = false, max_width = nil, max_height = nil)
  self.executor = executor
  self.disable_horizontal = disable_horizontal
  self.disable_vertical = disable_vertical
  self.max_width = max_width
  self.max_height = max_height
end

Instance Attribute Details

#last_state_positionObject

Returns the value of attribute last_state_position.



7
8
9
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 7

def last_state_position
  @last_state_position
end

Instance Method Details

#current_positionObject



24
25
26
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 24

def current_position
  last_state_position
end

#entire_sizeApplitools::RectangleSize

Gets the entire size of the frame.

Returns:

  • (Applitools::RectangleSize)

    The entire size of the frame.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 64

def entire_size
  viewport_size = Applitools::Utils::EyesSeleniumUtils.extract_viewport_size(executor)
  result = Applitools::Utils::EyesSeleniumUtils.current_frame_content_entire_size(executor)
  logger.info "Entire size: #{result}"
  result.width = [result.width, max_width].min unless max_width.nil?
  result.height = [result.height, max_height].min unless max_height.nil?
  result.width = [viewport_size.width, result.width].min if disable_horizontal
  result.height = [viewport_size.height, result.height].min if disable_vertical
  logger.info "Actual size to scroll: #{result}"
  result
end

#force_offsetObject



55
56
57
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 55

def force_offset
  Applitools::Location.from_any_attribute last_state_position
end

#position=(value) ⇒ Object Also known as: scroll_to



47
48
49
50
51
52
53
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 47

def position=(value)
  Applitools::ArgumentGuard.not_nil(value, 'value')
  logger.info "Setting position to: #{value}"
  Applitools::Utils::EyesSeleniumUtils.translate_to(executor, value)
  logger.info 'Done!'
  self.last_state_position = value
end

#restore_state(value) ⇒ Object

Restore last state position.

Parameters:

  • value (Applitools::Location)

    The location.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 35

def restore_state(value)
  transforms = value.values.select { |el| !el.empty? }
  Applitools::Utils::EyesSeleniumUtils.set_transforms(executor, value)
  if transforms.empty?
    self.last_state_position = Applitools::Location::TOP_LEFT
  else
    positions = transforms.map { |s| get_position_from_transform(s) }
    positions.each { |p| raise Applitools::EyesError.new 'Got different css positions!' unless p == positions[0] }
    self.last_state_position = positions[0]
  end
end

#stateObject



28
29
30
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 28

def state
  Applitools::Utils::EyesSeleniumUtils.current_transforms(executor)
end