1515import base64
1616import os
1717from typing import Any , Dict , Optional , Tuple , Union
18+
1819from appium .webdriver .extensions .flutter_integration .scroll_directions import ScrollDirection
1920from appium .webdriver .flutter_finder import FlutterFinder
2021from appium .webdriver .webdriver import WebDriver
2122from appium .webdriver .webelement import WebElement
2223
2324
2425class FlutterCommand :
25-
26+
2627 def __init__ (self , driver : WebDriver ) -> None :
2728 self .driver = driver
28-
29- # wait commands
30-
29+
30+ # wait commands
31+
3132 def wait_for_visible (self , locator : Union [WebElement , FlutterFinder ], time_out : Optional [float ] = None ) -> None :
3233 """
3334 Waits for a element to become visible.
3435
3536 Args:
3637 locator (Union[WebElement, FlutterFinder]): The element to wait for; can be a WebElement or a FlutterFinder.
3738 time_out (Optional[float]): Maximum wait time in seconds. Defaults to a predefined timeout if not specified.
38-
39- Returns:
40- None:
39+
40+ Returns:
41+ None:
4142 """
4243 opts : Dict [str , Union [WebElement , Dict [str , str ], float ]] = {}
4344 if isinstance (locator , WebElement ):
@@ -49,17 +50,16 @@ def wait_for_visible(self, locator: Union[WebElement, FlutterFinder], time_out:
4950
5051 self .execute_flutter_command ('waitForVisible' , opts )
5152
52-
5353 def wait_for_invisible (self , locator : Union [WebElement , FlutterFinder ], time_out : Optional [float ] = None ) -> None :
5454 """
5555 Waits for a element to become invisible.
5656
5757 Args:
5858 locator (Union[WebElement, FlutterFinder]): The element to wait for; can be a WebElement or a FlutterFinder.
5959 time_out (Optional[float]): Maximum wait time in seconds. Defaults to a predefined timeout if not specified.
60-
60+
6161 Returns:
62- None:
62+ None:
6363 """
6464 opts : Dict [str , Union [WebElement , Dict [str , str ], float ]] = {}
6565 if isinstance (locator , WebElement ):
@@ -68,95 +68,95 @@ def wait_for_invisible(self, locator: Union[WebElement, FlutterFinder], time_out
6868 opts ['locator' ] = locator .to_dict ()
6969 if time_out is not None :
7070 opts ['timeout' ] = time_out
71-
71+
7272 self .execute_flutter_command ('waitForAbsent' , opts )
7373
7474 # flutter action commands
75-
75+
7676 def perform_double_click (self , element : WebElement , offset : Optional [Tuple [int , int ]] = None ) -> None :
7777 """
7878 Performs a double-click on the given element, with an optional offset.
7979
8080 Args:
8181 element (WebElement): The element to double-click on. This parameter is required.
8282 offset (Optional[Tuple[int, int]]): The x and y offsets from the element to click at. If not specified, the click is performed at the element's center.
83-
83+
8484 Returns:
8585 None:
8686 """
87- opts : Dict [str , Union [WebElement , Dict [str , int ]]] = {' origin' : element }
87+ opts : Dict [str , Union [WebElement , Dict [str , int ]]] = {" origin" : element }
8888 if offset is not None :
8989 opts ['offset' ] = {'x' : offset [0 ], 'y' : offset [1 ]}
9090 self .execute_flutter_command ('doubleClick' , opts )
91-
91+
9292 def perform_long_press (self , element : WebElement , offset : Optional [Tuple [int , int ]] = None ) -> None :
9393 """
9494 Performs a long press on the given element, with an optional offset.
9595
9696 Args:
9797 element (WebElement): The element to perform the long press on. This parameter is required.
9898 offset (Optional[Tuple[int, int]]): The x and y offsets from the element to perform the long press at. If not specified, the long press is performed at the element's center.
99-
99+
100100 Returns:
101101 None:
102102 """
103- opts : Dict [str , Union [WebElement , Dict [str , int ]]]= {'origin' : element }
103+ opts : Dict [str , Union [WebElement , Dict [str , int ]]] = {'origin' : element }
104104 if offset is not None :
105105 opts ['offset' ] = {'x' : offset [0 ], 'y' : offset [1 ]}
106106 self .execute_flutter_command ('longPress' , opts )
107-
107+
108108 def perform_drag_and_drop (self , source : WebElement , target : WebElement ) -> None :
109109 """
110110 Performs a drag-and-drop operation from a source element to a target element.
111111
112112 Args:
113113 source (WebElement): The element to drag from.
114114 target (WebElement): The element to drop onto.
115-
115+
116116 Returns:
117117 None:
118118 """
119119 self .execute_flutter_command ('dragAndDrop' , {'source' : source , 'target' : target })
120-
120+
121121 def scroll_till_visible (self , scroll_to : FlutterFinder , scroll_direction : ScrollDirection = ScrollDirection .DOWN , ** opts : Any ) -> WebElement :
122122 """
123123 Scrolls until the specified element becomes visible.
124124
125125 Args:
126126 scroll_to (FlutterFinder): The Flutter element to scroll to.
127127 scroll_direction (ScrollDirection): The direction to scroll up or down. Defaults to `ScrollDirection.DOWN`.
128-
128+
129129 KeywordArgs:
130- scrollView (str): The view of the scroll.
131- delta (int): delta for the scroll
132- maxScrolls (int): Max times to scroll
133- settleBetweenScrollsTimeout (int): settle timeout
134- dragDuration (int): time gap between each scroll
135-
130+ scrollView (str): The view of the scroll. Default value is 'Scrollable'
131+ delta (int): delta for the scroll. Default value is 64
132+ maxScrolls (int): Max times to scroll. Default value is 15
133+ settleBetweenScrollsTimeout (int): settle timeout in milliseconds. Default value is 5000ms
134+ dragDuration (int): time gap between each scroll in milliseconds. Default value is 100ms
135+
136136 Returns:
137137 Webelement: scrolled element
138138 """
139139 opts ['finder' ] = scroll_to .to_dict ()
140- opts ['scrollDirection' ] = scroll_direction .as_string ()
140+ opts ['scrollDirection' ] = scroll_direction .value
141141 return self .execute_flutter_command ('scrollTillVisible' , opts )
142-
142+
143143 def inject_mock_image (self , value : str ) -> str :
144144 """
145145 Injects a mock image to the device. The input can be a file path or a base64-encoded string.
146146
147147 Args:
148148 value (str): The file path of the image or a base64-encoded string.
149-
149+
150150 Returns:
151151 str: Image ID of the injected image.
152152 """
153- if os .path .isfile (value ):
153+ if os .path .isfile (value ):
154154 with open (value , 'rb' ) as image_file :
155155 base64_encoded_image = base64 .b64encode (image_file .read ()).decode ('utf-8' )
156156 else :
157157 base64_encoded_image = value
158158 return self .execute_flutter_command ('injectImage' , {'base64Image' : base64_encoded_image })
159-
159+
160160 def activate_injected_image (self , image_id : str ) -> None :
161161 """
162162 Activates an injected image with image ID.
@@ -168,18 +168,18 @@ def activate_injected_image(self, image_id: str) -> None:
168168 None:
169169 """
170170 self .execute_flutter_command ('activateInjectedImage' , {'imageId' : image_id })
171-
171+
172172 def execute_flutter_command (self , scriptName : str , params : dict ) -> Any :
173173 """
174174 Executes a Flutter command by sending a script and parameters to the flutter integration driver.
175175
176176 Args:
177- scriptName (str): The name of the Flutter command to execute.
177+ scriptName (str): The name of the Flutter command to execute.
178178 This will be prefixed with 'flutter:' when passed to the driver.
179179 params (dict): A dictionary of parameters to be passed along with the Flutter command.
180180
181181 Returns:
182- Any: The result of the command execution. The return value depends on the
182+ Any: The result of the command execution. The return value depends on the
183183 specific Flutter command being executed.
184184 """
185- return self .driver .execute_script (f'flutter: { scriptName } ' , params )
185+ return self .driver .execute_script (f'flutter: { scriptName } ' , params )
0 commit comments