Class: Applitools::Selenium::MoveToRegionVisibilityStrategy

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

Constant Summary collapse

VISIBILITY_OFFSET =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_positionObject

Returns the value of attribute original_position.



10
11
12
# File 'lib/applitools/selenium/move_to_region_visibility_strategy.rb', line 10

def original_position
  @original_position
end

Instance Method Details

#move_to_region(position_provider, location) ⇒ Object

Set the location of the position provider.

Parameters:

  • position_provider (Applitools::Selenium::CssTranslatePositionProvider, Applitools::Selenium::ScrollPositionProvider)

    The position provider type (e.g. Applitools::Selenium::CssTranslatePositionProvider, Applitools::Selenium::ScrollPositionProvider).

  • location (Applitools::Location)

    The location to move to.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/applitools/selenium/move_to_region_visibility_strategy.rb', line 18

def move_to_region(position_provider, location)
  logger.info 'Getting current position state...'
  self.original_position = position_provider.state

  dst_x = location.x - VISIBILITY_OFFSET
  dst_y = location.y - VISIBILITY_OFFSET

  dst_x = 0 if dst_x < 0
  dst_y = 0 if dst_y < 0

  logger.info "Done! Setting position to #{location}..."

  position_provider.position = Applitools::Location.new(dst_x, dst_y)
  logger.info 'Done!'
end

#return_to_original_position(position_provider) ⇒ Object

Returns the position provider to its original position.

Parameters:

  • position_provider (Applitools::Selenium::CssTranslatePositionProvider, Applitools::Selenium::ScrollPositionProvider)

    The position provider type (e.g. Applitools::Selenium::CssTranslatePositionProvider, Applitools::Selenium::ScrollPositionProvider).



38
39
40
41
42
43
# File 'lib/applitools/selenium/move_to_region_visibility_strategy.rb', line 38

def return_to_original_position(position_provider)
  return if original_position.nil?
  logger.info 'Returning to original position...'
  position_provider.restore_state original_position
  logger.info 'Done!'
end