11from appium .webdriver .webelement import WebElement
22from .keywordgroup import KeywordGroup
33from AppiumFlutterLibrary .finder import ElementFinder
4+ from appium_flutter_finder import FlutterElement
5+ from typing import Optional
46
57def isstr (s ):
68 return isinstance (s , str )
@@ -35,48 +37,64 @@ def clear_text(self, locator):
3537 except Exception as err :
3638 raise err
3739
38- def click_element (self , locator ) :
40+ def click_element (self , locator : str | FlutterElement ) -> None :
3941 """Tap the specified element.
4042
4143 If the element does not support tapping an error
4244 will be raised.
4345 """
44- element = self ._find_element (locator )
46+ if isinstance (locator , FlutterElement ):
47+ element = locator
48+ else :
49+ element = self ._find_element (locator )
50+ 4551 self ._info ("Clicking on element %s" % locator )
4652 try :
4753 element .click ()
4854 except Exception as err :
4955 raise err
5056
51- def element_should_be_visible (self , locator ):
57+ def element_should_be_visible (self , locator : str | FlutterElement ):
5258 """Verify if the element is visible using FlutterDriver.waitFor().
5359
5460 If the element isn't visible raise an Assertion Error.
5561 """
56- element = self ._find_element (locator )
62+ if isinstance (locator , FlutterElement ):
63+ element = locator
64+ else :
65+ element = self ._find_element (locator )
66+ 5767 if not self ._is_visible (element ):
5868 raise AssertionError ("Element '%s' should be visible but not" % locator )
5969
60- def element_text_should_be (self , locator , text ):
70+ def element_text_should_be (self , locator : str | FlutterElement , text ):
6171 """Verify if the element text is equal to provided text.
6272
6373 If the text isn't equal raise an Assertion Error.
6474
6575 If the element does not support getText() raise an error.
6676 """
67- element = self ._find_element (locator )
77+ if isinstance (locator , FlutterElement ):
78+ element = locator
79+ else :
80+ element = self ._find_element (locator )
81+ 6882 if element .text != text :
6983 raise AssertionError ("Element '%s' text should be '%s' but is '%s'." %
7084 (locator , text , element .text ))
7185
72- def element_text_should_not_be (self , locator , text ):
86+ def element_text_should_not_be (self , locator : str | FlutterElement , text ):
7387 """Verify if the element text is not equal to provided text.
7488
7589 If the text isn't equal raise an Assertion Error.
7690
7791 If the element does not support getText() raise an error.
7892 """
79- element = self ._find_element (locator )
93+ if isinstance (locator , FlutterElement ):
94+ element = locator
95+ else :
96+ element = self ._find_element (locator )
97+ 8098 if element .text == text :
8199 raise AssertionError ("Element '%s' text should not be '%s' but is." %
82100 (locator , text ))
@@ -86,7 +104,7 @@ def get_element(self, locator):
86104 """
87105 return self ._find_element (locator )
88106
89- def get_element_text (self , locator ):
107+ def get_element_text (self , locator : str | FlutterElement ):
90108 """Returns element text
91109
92110 If the element does not support getText() raise an error.
@@ -95,6 +113,26 @@ def get_element_text(self, locator):
95113 self ._info ("Element '%s' text is '%s' " % (locator , text ))
96114 return text
97115
116+ def get_element_descendant (self , of : str , matching : str ) -> FlutterElement :
117+ """Returns the element's descendant
118+
119+ Params:
120+ of: locator for the parent element
121+ matching: locator for the child element
122+ """
123+ application = self ._current_application ()
124+ return self ._element_finder ._get_descendant (application , of , matching )
125+ 126+ def get_element_ancestor (self , of : str , matching : str ) -> FlutterElement :
127+ """Returns the element's ancestor
128+
129+ Params:
130+ of: locator for the parent element
131+ matching: locator for the child element
132+ """
133+ applicaiton = self .current_application ()
134+ return self ._element_finder ._get_ancestor (applicaiton , of , matching )
135+ 98136 def _is_visible (self , element ):
99137 application = self ._current_application ()
100138 application .execute_script ('flutter:waitFor' , element .id , 1 )
@@ -104,8 +142,12 @@ def _find_element(self, locator):
104142 application = self ._current_application ()
105143 return self ._element_finder .find (application , locator )
106144
107- def _get_text (self , locator ):
108- element = self ._find_element (locator )
145+ def _get_text (self , locator : str | FlutterElement ) -> Optional [str ]:
146+ if isinstance (locator , FlutterElement ):
147+ element = locator
148+ else :
149+ element = self ._find_element (locator )
150+ 109151 if element is not None :
110152 return element .text
111153 return None
0 commit comments