11import time
2- from typing import Tuple , Literal
2+ from typing import Tuple , Literal , Optional
33
4+ from selenium .webdriver .common .actions import interaction
45from selenium .webdriver .common .actions .action_builder import ActionBuilder
56from selenium .webdriver .common .actions .pointer_actions import PointerActions
7+ from selenium .webdriver .common .actions .pointer_input import PointerInput
68
79from screens .element_interactor import ElementInteractor
810from appium .webdriver .extensions .action_helpers import ActionHelpers , ActionChains
@@ -23,15 +25,20 @@ def click(
2325 element = self .element (locator , condition = condition )
2426 element .click ()
2527
26- def tap (self , locator , ** kwargs ):
27- """Taps on an element using ActionHelpers."""
28+ def tap (self , locator : Locator , duration : float = 500 , ** kwargs ):
29+ """Taps on an element using ActionHelpers.
30+ Taps on an particular place with up to five fingers, holding for a
31+ certain duration
32+
33+ :param locator: locator of an element
34+ :param duration: length of time to tap, in ms"""
2835 try :
2936 element = self .element (locator , condition = "clickable" , ** kwargs )
3037 location = element .location
3138 size = element .size
3239 x = location ["x" ] + size ["width" ] // 2
3340 y = location ["y" ] + size ["height" ] // 2
34- self .driver .tap ([(x , y )])
41+ self .driver .tap ([(x , y )], duration = duration )
3542 except Exception as e :
3643 print (f"Error during tap action: { e } " )
3744
@@ -43,7 +50,7 @@ def swipe(
4350 relative_end_y : float ,
4451 duration_ms : int = 200 ,
4552 ) -> None :
46- size = self .driver . get_window_size ()
53+ size = self .get_screen_size ()
4754 width = size ["width" ]
4855 height = size ["height" ]
4956 start_x = int (width * relative_start_x )
@@ -58,6 +65,41 @@ def swipe(
5865 duration_ms = duration_ms ,
5966 )
6067
68+ def scroll (
69+ self ,
70+ directions : Literal ["down" , "up" ] = "down" ,
71+ start_ratio : float = 0.7 ,
72+ end_ratio : float = 0.3 ,
73+ ):
74+ """
75+ Scrolls down the screen with customizable scroll size.
76+
77+ :param directions: up or down:
78+ :param start_ratio: Percentage (0-1) from where the scroll starts
79+ :type end_ratio: Percentage (0-1) where the scroll ends.
80+ USAGE:
81+ DOWN example
82+ start_y = int(height * 0.7)
83+ end_y = int(height * 0.3)
84+ UP example
85+ start_y = int(height * 0.3)
86+ end_y = int(height * 0.7)
87+ """
88+ size = self .get_screen_size ()
89+ width = size ["width" ]
90+ height = size ["height" ]
91+ start_x = width // 2
92+ if directions == "down" :
93+ start_y = int (height * start_ratio )
94+ end_y = int (height * end_ratio )
95+ elif directions == "up" :
96+ start_y = int (height * end_ratio )
97+ end_y = int (height * start_ratio )
98+ else :
99+ raise ValueError ("Direction must be 'down' or 'up'" )
100+
101+ self .scroll_by_coordinates (start_x , start_y , start_x , end_y )
102+
61103 def type (self , locator : Locator , text : str ):
62104 element = self .element (locator )
63105 element .send_keys (text )
@@ -71,8 +113,7 @@ def double_tap(
71113 """Double taps on an element."""
72114 try :
73115 element = self .element (locator , condition = condition , ** kwargs )
74- action = ActionHelpers ()
75- action .double_tap (element ).perform ()
116+ # TODO
76117 except Exception as e :
77118 print (f"Error during double tap action: { e } " )
78119
0 commit comments