11import time
22from typing import Tuple , Literal
33
4+ from selenium .webdriver .common .actions .action_builder import ActionBuilder
5+ from selenium .webdriver .common .actions .pointer_actions import PointerActions
6+
47from screens .element_interactor import ElementInteractor
58from appium .webdriver .extensions .action_helpers import ActionHelpers , ActionChains
69
@@ -21,22 +24,57 @@ def click(
2124 element .click ()
2225
2326 def tap (self , locator , ** kwargs ):
24- element = self .element (locator , condition = "clickable" , ** kwargs )
25- self .driver .tap ()
26- action_helpers = ActionHelpers ()
27- action_helpers .tap (element )
28-
29- def tap_by_coordinates (self ):
30- pass
31-
32- def swipe (self ):
33- pass
34-
35- def type (self ):
36- pass
37-
38- def double_tap (self ):
39- pass
27+ """Taps on an element using ActionHelpers."""
28+ try :
29+ element = self .element (locator , condition = "clickable" , ** kwargs )
30+ location = element .location
31+ size = element .size
32+ x = location ["x" ] + size ["width" ] // 2
33+ y = location ["y" ] + size ["height" ] // 2
34+ self .driver .tap ([(x , y )])
35+ except Exception as e :
36+ print (f"Error during tap action: { e } " )
37+
38+ def swipe (
39+ self ,
40+ relative_start_x : float ,
41+ relative_start_y : float ,
42+ relative_end_x : float ,
43+ relative_end_y : float ,
44+ duration_ms : int = 200 ,
45+ ) -> None :
46+ size = self .driver .get_window_size ()
47+ width = size ["width" ]
48+ height = size ["height" ]
49+ start_x = int (width * relative_start_x )
50+ start_y = int (height * relative_start_y )
51+ end_x = int (width * relative_end_x )
52+ end_y = int (height * relative_end_y )
53+ self .driver .swipe (
54+ start_x = start_x ,
55+ start_y = start_y ,
56+ end_x = end_x ,
57+ end_y = end_y ,
58+ duration_ms = duration_ms ,
59+ )
60+
61+ def type (self , locator : Locator , text : str ):
62+ element = self .element (locator )
63+ element .send_keys (text )
64+
65+ def double_tap (
66+ self ,
67+ locator : Locator ,
68+ condition : Literal ["clickable" , "visible" , "present" ] = "clickable" ,
69+ ** kwargs ,
70+ ):
71+ """Double taps on an element."""
72+ try :
73+ element = self .element (locator , condition = condition , ** kwargs )
74+ action = ActionHelpers ()
75+ action .double_tap (element ).perform ()
76+ except Exception as e :
77+ print (f"Error during double tap action: { e } " )
4078
4179 def long_press (self ):
4280 pass
0 commit comments