Skip to content

Commit

Permalink
feat: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
MummanaSubramanya committed Sep 20, 2024
1 parent f9e1630 commit 7694af1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import base64
import os
from typing import Any, Optional, Tuple, Union
from typing import Any, Dict, Optional, Tuple, Union
from appium.webdriver.extensions.flutter_integration.scroll_directions import ScrollDirection
from appium.webdriver.flutter_finder import FlutterFinder
from appium.webdriver.webdriver import WebDriver
Expand All @@ -39,10 +39,13 @@ def wait_for_visible(self, locator: Union[WebElement, FlutterFinder], time_out:
Returns:
None:
"""
opts: Dict[str, Union[WebElement, Dict[str, str], float]] = {}
if isinstance(locator, WebElement):
opts = {'element': locator, 'timeout': time_out}
opts['element'] = locator
else:
opts = {'locator': locator.to_dict(), 'timeout': time_out}
opts['locator'] = locator.to_dict()
if time_out is not None:
opts['timeout'] = time_out

self.execute_flutter_command('waitForVisible', opts)

Expand All @@ -58,10 +61,13 @@ def wait_for_invisible(self, locator: Union[WebElement, FlutterFinder], time_out
Returns:
None:
"""
opts: Dict[str, Union[WebElement, Dict[str, str], float]] = {}
if isinstance(locator, WebElement):
opts = {'element': locator, 'timeout': time_out}
opts['element'] = locator
else:
opts = {'locator': locator.to_dict(), 'timeout': time_out}
opts['locator'] = locator.to_dict()
if time_out is not None:
opts['timeout'] = time_out

self.execute_flutter_command('waitForAbsent', opts)

Expand All @@ -78,7 +84,7 @@ def perform_double_click(self, element: WebElement, offset: Optional[Tuple[int,
Returns:
None:
"""
opts = {'origin': element}
opts: Dict[str, Union[WebElement, Dict[str, int]]] = {'origin': element}
if offset is not None:
opts['offset'] = {'x': offset[0], 'y': offset[1]}
self.execute_flutter_command('doubleClick', opts)
Expand All @@ -94,7 +100,7 @@ def perform_long_press(self, element: WebElement, offset: Optional[Tuple[int, in
Returns:
None:
"""
opts = {'origin': element}
opts: Dict[str, Union[WebElement, Dict[str, int]]]= {'origin': element}
if offset is not None:
opts['offset'] = {'x': offset[0], 'y': offset[1]}
self.execute_flutter_command('longPress', opts)
Expand All @@ -112,13 +118,13 @@ def perform_drag_and_drop(self, source: WebElement, target: WebElement) -> None:
"""
self.execute_flutter_command('dragAndDrop', {'source': source, 'target': target})

def scroll_till_visible(self, scroll_to: FlutterFinder, scroll_direction: Optional[ScrollDirection] = ScrollDirection.DOWN, **opts: Any) -> WebElement:
def scroll_till_visible(self, scroll_to: FlutterFinder, scroll_direction: ScrollDirection = ScrollDirection.DOWN, **opts: Any) -> WebElement:
"""
Scrolls until the specified element becomes visible.
Args:
scroll_to (FlutterFinder): The Flutter element to scroll to.
scroll_direction (Optional[ScrollDirection]): The direction to scroll up or down. Defaults to `ScrollDirection.DOWN`.
scroll_direction (ScrollDirection): The direction to scroll up or down. Defaults to `ScrollDirection.DOWN`.
KeywordArgs:
scrollView (str): The view of the scroll.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class ScrollDirection(Enum):
UP = 'up'
DOWN = 'down'

def as_string(self):
def as_string(self) -> str:
return str(self.value)
2 changes: 1 addition & 1 deletion appium/webdriver/flutter_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def by_flutter_text_containing(value: str) -> 'FlutterFinder':
def to_dict(self) -> dict:
return { 'using': self.using, 'value': self.value}

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

16 changes: 8 additions & 8 deletions test/functional/flutter_integration/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class TestFlutterCommands(BaseTestCase):

def test_wait_command(self):
def test_wait_command(self) -> None:
self.__open_screen('Lazy Loading')

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

def test_scroll_till_visible_command(self):
def test_scroll_till_visible_command(self) -> None:
self.__open_screen('Vertical Swiping')

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

def test_scroll_till_visible_with_scroll_params_command(self):
def test_scroll_till_visible_with_scroll_params_command(self) -> None:
self.__open_screen('Vertical Swiping')

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

def test_double_click_command(self):
def test_double_click_command(self) -> None:
self.__open_screen('Double Tap')

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

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

def test_long_press_command(self):
def test_long_press_command(self) -> None:
self.__open_screen('Long Press')

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

def test_drag_and_drop_command(self):
def test_drag_and_drop_command(self) -> None:
self.__open_screen('Drag & Drop')

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

def test_camera_mocking(self):
def test_camera_mocking(self) -> None:
self.__open_screen('Image Picker')

success_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'success_qr.png')
Expand Down
10 changes: 5 additions & 5 deletions test/functional/flutter_integration/finder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class TestFlutterFinders(BaseTestCase):

def test_by_flutter_key(self):
def test_by_flutter_key(self) -> None:
user_name_field_finder = FlutterFinder.by_flutter_key('username_text_field')
user_name_field = self.driver.find_element(*user_name_field_finder.as_args())
assert user_name_field.text == 'admin'
Expand All @@ -29,25 +29,25 @@ def test_by_flutter_key(self):
user_name_field = self.driver.find_element(*user_name_field_finder.as_args()).send_keys('admin123')
assert user_name_field.text == 'admin123'

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

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

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

def test_by_flutter_text_containing(self):
def test_by_flutter_text_containing(self) -> None:
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
login_button.click()
vertical_swipe_label = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Vertical')
assert vertical_swipe_label.text == 'Vertical Swiping'

def test_by_flutter_semantics_label(self):
def test_by_flutter_semantics_label(self) -> None:
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
login_button.click()
element = self.flutter_command.scroll_till_visible(FlutterFinder.by_flutter_text('Lazy Loading'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
from typing import Any, Dict

def get_desired_capabilities(platform_name: str) -> Dict[str, Any]:
desired_caps: Dict[str, Any] = {}
if platform_name == 'android':
desired_caps: Dict[str, Any] = {
desired_caps.update({
'platformName': 'Android',
'deviceName': 'Android Emulator',
'newCommandTimeout': 240,
'uiautomator2ServerInstallTimeout': 120000,
'adbExecTimeout': 120000,
'app': os.getenv('FLUTTER_ANDROID_APP')
}
})
else:
desired_caps: Dict[str, Any] = {
desired_caps.update({
'deviceName': os.getenv('IPHONE_MODEL'),
'platformName': 'iOS',
'platformVersion': os.getenv('IOS_VERSION'),
Expand All @@ -35,6 +36,6 @@ def get_desired_capabilities(platform_name: str) -> Dict[str, Any]:
'wdaLocalPort': 8100,
'eventTimings': True,
'app': os.getenv('FLUTTER_IOS_APP')
}
})

return desired_caps

0 comments on commit 7694af1

Please sign in to comment.