from appium.webdriver.common.appiumby import AppiumBy from selenium.webdriver import Keys from helpers.platform.coordinates.models import Coordinate def scroll_page(driver, direction, small_scroll=False, times=None): y_coords = {} hide_keyboard(driver) if small_scroll: if direction == 'down': y_coords = {'fromY': 482, 'toY': 318} elif direction == 'up': y_coords = {'fromY': 318, 'toY': 482} params = {'fromX': 5, 'toX': 5, 'duration': 0.2} params.update(y_coords) if times is None: driver.execute_script( 'mobile:dragFromToForDuration', params) else: for _ in range(times): driver.execute_script( 'mobile:dragFromToForDuration', params) else: if direction == 'down': y_coords = {'fromY': 582, 'toY': 228} elif direction == 'up': y_coords = {'fromY': 228, 'toY': 582} params = {'fromX': 5, 'toX': 5, 'duration': 0.2} params.update(y_coords) if times is None: driver.execute_script( 'mobile:dragFromToForDuration', params) else: for _ in range(times): driver.execute_script( 'mobile:dragFromToForDuration', params) def hide_webview_keyboard(driver): driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="Done").click() def hide_keyboard(driver): try: active = driver.switch_to.active_element active.send_keys(Keys.RETURN) except Exception: print('[DEBUG] There is no active keyboard.') def navigate_back_in_browser(context): context.driver.activate_app(context.bundle_id) def tap_at_coordinate(driver, coord: Coordinate): driver.execute_script("mobile: tap", { "x": coord.x, "y": coord.y })