Class: Applitools::Selenium::CssTranslatePositionProvider
- Inherits:
-
Object
- Object
- Applitools::Selenium::CssTranslatePositionProvider
- Extended by:
- Forwardable
- Includes:
- CssTransform
- Defined in:
- lib/applitools/selenium/css_translate_position_provider.rb
Instance Attribute Summary collapse
-
#last_state_position ⇒ Object
Returns the value of attribute last_state_position.
Instance Method Summary collapse
- #current_position ⇒ Object
-
#entire_size(_image_width, _image_height) ⇒ Applitools::RectangleSize
Gets the entire size of the frame.
- #force_offset ⇒ Object
-
#initialize(executor, disable_horizontal = false, disable_vertical = false, max_width = nil, max_height = nil) ⇒ CssTranslatePositionProvider
constructor
Initialize a class instance.
- #position=(value) ⇒ Object (also: #scroll_to)
-
#restore_state(value) ⇒ Object
Restore last state position.
- #state ⇒ Object
Constructor Details
#initialize(executor, disable_horizontal = false, disable_vertical = false, max_width = nil, max_height = nil) ⇒ CssTranslatePositionProvider
Initialize a class instance.
21 22 23 24 25 26 27 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 21 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_position ⇒ Object
Returns the value of attribute last_state_position.
12 13 14 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 12 def last_state_position @last_state_position end |
Instance Method Details
#current_position ⇒ Object
29 30 31 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 29 def current_position last_state_position end |
#entire_size(_image_width, _image_height) ⇒ Applitools::RectangleSize
Gets the entire size of the frame.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 74 def entire_size(_image_width, _image_height) = Applitools::Utils::EyesSeleniumUtils.(executor) result = Applitools::Utils::EyesSeleniumUtils.current_frame_content_entire_size(executor) logger.info "Entire size: #{result}" result.width = max_width unless max_width.nil? result.height = max_height unless max_height.nil? result.width = [.width, result.width].min if disable_horizontal result.height = [.height, result.height].min if disable_vertical logger.info "Actual size to scroll: #{result}" result # return result unless executor.frame_chain.empty? # spp = Applitools::Selenium::ScrollPositionProvider.new(executor) # original_scroll_position = spp.current_position # spp.scroll_to_bottom_right # bottom_right_position = spp.current_position # spp.restore_state(original_scroll_position) # Applitools::RectangleSize.new(bottom_right_position.x + image_width, bottom_right_position.y + image_height) end |
#force_offset ⇒ Object
64 65 66 67 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 64 def force_offset Applitools::Location.from_any_attribute last_state_position # Applitools::Location::TOP_LEFT end |
#position=(value) ⇒ Object Also known as: scroll_to
54 55 56 57 58 59 60 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 54 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 40 def restore_state(value) Applitools::Utils::EyesSeleniumUtils.set_current_transforms(executor, 'translate(10px, 0px)') transforms = value.values.compact.map(&:to_s).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 |
#state ⇒ Object
33 34 35 |
# File 'lib/applitools/selenium/css_translate_position_provider.rb', line 33 def state Applitools::Utils::EyesSeleniumUtils.current_transforms(executor) end |