1414# KIND, either express or implied. See the License for the
1515# specific language governing permissions and limitations
1616# under the License.
17- from .input_device import InputDevice
18- from .interaction import POINTER , POINTER_KINDS
17+ import typing
1918
2019from selenium .common .exceptions import InvalidArgumentException
2120from selenium .webdriver .remote .webelement import WebElement
21+ from .input_device import InputDevice
22+ from .interaction import POINTER , POINTER_KINDS
2223
2324
2425class PointerInput (InputDevice ):
25-
2626 DEFAULT_MOVE_DURATION = 250
2727
2828 def __init__ (self , kind , name ):
@@ -34,20 +34,25 @@ def __init__(self, kind, name):
3434 self .name = name
3535
3636 def create_pointer_move (self , duration = DEFAULT_MOVE_DURATION , x = 0 , y = 0 , origin = None , ** kwargs ):
37- action = dict (type = "pointerMove" , duration = duration )
38- action ["x" ] = x
39- action ["y" ] = y
40- action .update (** kwargs )
37+ action = {
38+ "type" : "pointerMove" ,
39+ "duration" : duration ,
40+ "x" : x ,
41+ "y" : y ,
42+ ** kwargs
43+ }
4144 if isinstance (origin , WebElement ):
4245 action ["origin" ] = {"element-6066-11e4-a52e-4f735466cecf" : origin .id }
43- elif origin :
46+ elif origin is not None :
4447 action ["origin" ] = origin
45-
4648 self .add_action (self ._convert_keys (action ))
4749
4850 def create_pointer_down (self , ** kwargs ):
49- data = dict (type = "pointerDown" , duration = 0 )
50- data .update (** kwargs )
51+ data = {
52+ "type" : "pointerDown" ,
53+ "duration" : 0 ,
54+ ** kwargs
55+ }
5156 self .add_action (self ._convert_keys (data ))
5257
5358 def create_pointer_up (self , button ):
@@ -65,15 +70,15 @@ def encode(self):
6570 "id" : self .name ,
6671 "actions" : self .actions }
6772
68- def _convert_keys (self , actions ):
73+ def _convert_keys (self , actions : typing . Dict [ str , typing . Any ] ):
6974 out = {}
70- for k in actions .keys ():
71- if actions [ k ] is None :
75+ for k , v in actions .items ():
76+ if v is None :
7277 continue
73- if k == "x" or k == "y" :
74- out [k ] = int (actions [ k ] )
78+ if k in ( "x" , "y" ) :
79+ out [k ] = int (v )
7580 continue
7681 splits = k .split ('_' )
7782 new_key = splits [0 ] + '' .join (v .title () for v in splits [1 :])
78- out [new_key ] = actions [ k ]
83+ out [new_key ] = v
7984 return out
0 commit comments