Skip to content

Commit 7694af1

Browse files
feat: fix code style
1 parent f9e1630 commit 7694af1

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

appium/webdriver/extensions/flutter_integration/flutter_commands.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import base64
1616
import os
17-
from typing import Any, Optional, Tuple, Union
17+
from typing import Any, Dict, Optional, Tuple, Union
1818
from appium.webdriver.extensions.flutter_integration.scroll_directions import ScrollDirection
1919
from appium.webdriver.flutter_finder import FlutterFinder
2020
from appium.webdriver.webdriver import WebDriver
@@ -39,10 +39,13 @@ def wait_for_visible(self, locator: Union[WebElement, FlutterFinder], time_out:
3939
Returns:
4040
None:
4141
"""
42+
opts: Dict[str, Union[WebElement, Dict[str, str], float]] = {}
4243
if isinstance(locator, WebElement):
43-
opts = {'element': locator, 'timeout': time_out}
44+
opts['element'] = locator
4445
else:
45-
opts = {'locator': locator.to_dict(), 'timeout': time_out}
46+
opts['locator'] = locator.to_dict()
47+
if time_out is not None:
48+
opts['timeout'] = time_out
4649

4750
self.execute_flutter_command('waitForVisible', opts)
4851

@@ -58,10 +61,13 @@ def wait_for_invisible(self, locator: Union[WebElement, FlutterFinder], time_out
5861
Returns:
5962
None:
6063
"""
64+
opts: Dict[str, Union[WebElement, Dict[str, str], float]] = {}
6165
if isinstance(locator, WebElement):
62-
opts = {'element': locator, 'timeout': time_out}
66+
opts['element'] = locator
6367
else:
64-
opts = {'locator': locator.to_dict(), 'timeout': time_out}
68+
opts['locator'] = locator.to_dict()
69+
if time_out is not None:
70+
opts['timeout'] = time_out
6571

6672
self.execute_flutter_command('waitForAbsent', opts)
6773

@@ -78,7 +84,7 @@ def perform_double_click(self, element: WebElement, offset: Optional[Tuple[int,
7884
Returns:
7985
None:
8086
"""
81-
opts = {'origin': element}
87+
opts: Dict[str, Union[WebElement, Dict[str, int]]] = {'origin': element}
8288
if offset is not None:
8389
opts['offset'] = {'x': offset[0], 'y': offset[1]}
8490
self.execute_flutter_command('doubleClick', opts)
@@ -94,7 +100,7 @@ def perform_long_press(self, element: WebElement, offset: Optional[Tuple[int, in
94100
Returns:
95101
None:
96102
"""
97-
opts = {'origin': element}
103+
opts: Dict[str, Union[WebElement, Dict[str, int]]]= {'origin': element}
98104
if offset is not None:
99105
opts['offset'] = {'x': offset[0], 'y': offset[1]}
100106
self.execute_flutter_command('longPress', opts)
@@ -112,13 +118,13 @@ def perform_drag_and_drop(self, source: WebElement, target: WebElement) -> None:
112118
"""
113119
self.execute_flutter_command('dragAndDrop', {'source': source, 'target': target})
114120

115-
def scroll_till_visible(self, scroll_to: FlutterFinder, scroll_direction: Optional[ScrollDirection] = ScrollDirection.DOWN, **opts: Any) -> WebElement:
121+
def scroll_till_visible(self, scroll_to: FlutterFinder, scroll_direction: ScrollDirection = ScrollDirection.DOWN, **opts: Any) -> WebElement:
116122
"""
117123
Scrolls until the specified element becomes visible.
118124
119125
Args:
120126
scroll_to (FlutterFinder): The Flutter element to scroll to.
121-
scroll_direction (Optional[ScrollDirection]): The direction to scroll up or down. Defaults to `ScrollDirection.DOWN`.
127+
scroll_direction (ScrollDirection): The direction to scroll up or down. Defaults to `ScrollDirection.DOWN`.
122128
123129
KeywordArgs:
124130
scrollView (str): The view of the scroll.

appium/webdriver/extensions/flutter_integration/scroll_directions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ class ScrollDirection(Enum):
44
UP = 'up'
55
DOWN = 'down'
66

7-
def as_string(self):
7+
def as_string(self) -> str:
88
return str(self.value)

appium/webdriver/flutter_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ def by_flutter_text_containing(value: str) -> 'FlutterFinder':
4646
def to_dict(self) -> dict:
4747
return { 'using': self.using, 'value': self.value}
4848

49-
def as_args(self) -> str:
49+
def as_args(self) -> tuple[str, str]:
5050
return self.using, self.value
5151

test/functional/flutter_integration/commands_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class TestFlutterCommands(BaseTestCase):
2323

24-
def test_wait_command(self):
24+
def test_wait_command(self) -> None:
2525
self.__open_screen('Lazy Loading')
2626

2727
message_field_finder = FlutterFinder.by_flutter_key('message_field')
@@ -40,7 +40,7 @@ def test_wait_command(self):
4040
self.flutter_command.wait_for_visible(message_field)
4141
assert len(self.driver.find_elements(*message_field_finder.as_args())) == 1
4242

43-
def test_scroll_till_visible_command(self):
43+
def test_scroll_till_visible_command(self) -> None:
4444
self.__open_screen('Vertical Swiping')
4545

4646
java_text_finder = FlutterFinder.by_flutter_text('Java')
@@ -57,7 +57,7 @@ def test_scroll_till_visible_command(self):
5757
assert second_element.get_attribute('displayed') == 'false'
5858
assert first_element.get_attribute('displayed') == 'true'
5959

60-
def test_scroll_till_visible_with_scroll_params_command(self):
60+
def test_scroll_till_visible_with_scroll_params_command(self) -> None:
6161
self.__open_screen('Vertical Swiping')
6262

6363
scroll_params = {'scrollView': FlutterFinder.by_flutter_type('Scrollable').to_dict(),
@@ -66,10 +66,10 @@ def test_scroll_till_visible_with_scroll_params_command(self):
6666
'settleBetweenScrollsTimeout': 5000,
6767
'dragDuration': 35
6868
}
69-
first_element = self.flutter_command.scroll_till_visible(FlutterFinder.by_flutter_text('Playwright'), **scroll_params)
69+
first_element = self.flutter_command.scroll_till_visible(FlutterFinder.by_flutter_text('Playwright'), scroll_direction=ScrollDirection.DOWN, **scroll_params)
7070
assert first_element.get_attribute('displayed') == 'true'
7171

72-
def test_double_click_command(self):
72+
def test_double_click_command(self) -> None:
7373
self.__open_screen('Double Tap')
7474

7575
double_tap_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'double_tap_button').find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Double Tap')
@@ -84,7 +84,7 @@ def test_double_click_command(self):
8484

8585
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Ok').click()
8686

87-
def test_long_press_command(self):
87+
def test_long_press_command(self) -> None:
8888
self.__open_screen('Long Press')
8989

9090
long_press_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'long_press_button')
@@ -94,15 +94,15 @@ def test_long_press_command(self):
9494
assert success_pop_up.text == 'It was a long press'
9595
assert success_pop_up.is_displayed() == True
9696

97-
def test_drag_and_drop_command(self):
97+
def test_drag_and_drop_command(self) -> None:
9898
self.__open_screen('Drag & Drop')
9999

100100
drag_element = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drag_me')
101101
drop_element = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drop_zone')
102102
self.flutter_command.perform_drag_and_drop(drag_element, drop_element)
103103
assert self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT,'The box is dropped').is_displayed() == True
104104

105-
def test_camera_mocking(self):
105+
def test_camera_mocking(self) -> None:
106106
self.__open_screen('Image Picker')
107107

108108
success_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'success_qr.png')

test/functional/flutter_integration/finder_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class TestFlutterFinders(BaseTestCase):
2222

23-
def test_by_flutter_key(self):
23+
def test_by_flutter_key(self) -> None:
2424
user_name_field_finder = FlutterFinder.by_flutter_key('username_text_field')
2525
user_name_field = self.driver.find_element(*user_name_field_finder.as_args())
2626
assert user_name_field.text == 'admin'
@@ -29,25 +29,25 @@ def test_by_flutter_key(self):
2929
user_name_field = self.driver.find_element(*user_name_field_finder.as_args()).send_keys('admin123')
3030
assert user_name_field.text == 'admin123'
3131

32-
def test_by_flutter_type(self):
32+
def test_by_flutter_type(self) -> None:
3333
login_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE,'ElevatedButton')
3434
assert login_button.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE, 'Text').text == 'Login'
3535

36-
def test_by_flutter_text(self):
36+
def test_by_flutter_text(self) -> None:
3737
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
3838
assert login_button.text == 'Login'
3939

4040
login_button.click()
4141
slider = self.driver.find_elements(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Slider')
4242
assert len(slider) == 1
4343

44-
def test_by_flutter_text_containing(self):
44+
def test_by_flutter_text_containing(self) -> None:
4545
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
4646
login_button.click()
4747
vertical_swipe_label = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Vertical')
4848
assert vertical_swipe_label.text == 'Vertical Swiping'
4949

50-
def test_by_flutter_semantics_label(self):
50+
def test_by_flutter_semantics_label(self) -> None:
5151
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
5252
login_button.click()
5353
element = self.flutter_command.scroll_till_visible(FlutterFinder.by_flutter_text('Lazy Loading'))

test/functional/flutter_integration/helper/desired_capabilities.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
from typing import Any, Dict
1717

1818
def get_desired_capabilities(platform_name: str) -> Dict[str, Any]:
19+
desired_caps: Dict[str, Any] = {}
1920
if platform_name == 'android':
20-
desired_caps: Dict[str, Any] = {
21+
desired_caps.update({
2122
'platformName': 'Android',
2223
'deviceName': 'Android Emulator',
2324
'newCommandTimeout': 240,
2425
'uiautomator2ServerInstallTimeout': 120000,
2526
'adbExecTimeout': 120000,
2627
'app': os.getenv('FLUTTER_ANDROID_APP')
27-
}
28+
})
2829
else:
29-
desired_caps: Dict[str, Any] = {
30+
desired_caps.update({
3031
'deviceName': os.getenv('IPHONE_MODEL'),
3132
'platformName': 'iOS',
3233
'platformVersion': os.getenv('IOS_VERSION'),
@@ -35,6 +36,6 @@ def get_desired_capabilities(platform_name: str) -> Dict[str, Any]:
3536
'wdaLocalPort': 8100,
3637
'eventTimings': True,
3738
'app': os.getenv('FLUTTER_IOS_APP')
38-
}
39+
})
3940

4041
return desired_caps

0 commit comments

Comments
 (0)