Path: blob/trunk/rb/lib/selenium/webdriver/common/interactions/scroll.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Interactions22#23# Action related to scrolling a wheel.24#25# @api private26#2728class Scroll < Interaction29def initialize(source:, origin: :viewport, duration: 0.25, **opts)30super(source)31@type = :scroll32@duration = duration * 100033@origin = origin34@x_offset = opts.delete(:x) || 035@y_offset = opts.delete(:y) || 036@delta_x = opts.delete(:delta_x) || 037@delta_y = opts.delete(:delta_y) || 03839raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?40end4142def assert_source(source)43raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? WheelInput44end4546def encode47{'type' => type.to_s,48'duration' => @duration.to_i,49'x' => @x_offset,50'y' => @y_offset,51'deltaX' => @delta_x,52'deltaY' => @delta_y,53'origin' => @origin.is_a?(Element) ? @origin : @origin.to_s}54end55end # PointerPress56end # Interactions57end # WebDriver58end # Selenium596061