Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/interactions/pointer_move.rb
1990 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
module Selenium
21
module WebDriver
22
module Interactions
23
#
24
# Action related to moving the pointer.
25
#
26
# @api private
27
#
28
29
class PointerMove < Interaction
30
include PointerEventProperties
31
32
VIEWPORT = :viewport
33
POINTER = :pointer
34
ORIGINS = [VIEWPORT, POINTER].freeze
35
36
def initialize(source, duration, x, y, **opts)
37
super(source)
38
@duration = duration * 1000
39
@x_offset = x
40
@y_offset = y
41
@origin = opts.delete(:element) || opts.delete(:origin) || :viewport
42
@type = :pointerMove
43
@opts = opts
44
end
45
46
def assert_source(source)
47
raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? PointerInput
48
end
49
50
def encode
51
process_opts.merge('type' => type.to_s,
52
'duration' => @duration.to_i,
53
'x' => @x_offset,
54
'y' => @y_offset,
55
'origin' => @origin)
56
end
57
end # PointerMove
58
end # Interactions
59
end # WebDriver
60
end # Selenium
61
62