Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions src/screens/base_screen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import time
from typing import Tuple, Literal

from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_actions import PointerActions

from screens.element_interactor import ElementInteractor
from appium.webdriver.extensions.action_helpers import ActionHelpers, ActionChains

Expand All @@ -15,28 +18,63 @@
def click(
self,
locator: Locator,
condition: Literal["clickable", "visible", "present"] = "clickable",

Check warning on line 21 in src/screens/base_screen.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Invalid type hints definitions and usages

'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types
):
element = self.element(locator, condition=condition)
element.click()

def tap(self, locator, **kwargs):
element = self.element(locator, condition="clickable", **kwargs)
self.driver.tap()
action_helpers = ActionHelpers()
action_helpers.tap(element)

def tap_by_coordinates(self):
pass

def swipe(self):
pass

def type(self):
pass

def double_tap(self):
pass
"""Taps on an element using ActionHelpers."""
try:
element = self.element(locator, condition="clickable", **kwargs)
location = element.location
size = element.size
x = location["x"] + size["width"] // 2
y = location["y"] + size["height"] // 2
self.driver.tap([(x, y)])
except Exception as e:
print(f"Error during tap action: {e}")

def swipe(
self,
relative_start_x: float,
relative_start_y: float,
relative_end_x: float,
relative_end_y: float,
duration_ms: int = 200,
) -> None:
size = self.driver.get_window_size()
width = size["width"]
height = size["height"]
start_x = int(width * relative_start_x)
start_y = int(height * relative_start_y)
end_x = int(width * relative_end_x)
end_y = int(height * relative_end_y)
self.driver.swipe(
start_x=start_x,
start_y=start_y,
end_x=end_x,
end_y=end_y,
duration_ms=duration_ms,
)

def type(self, locator: Locator, text: str):
element = self.element(locator)
element.send_keys(text)

def double_tap(
self,
locator: Locator,
condition: Literal["clickable", "visible", "present"] = "clickable",

Check warning on line 68 in src/screens/base_screen.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Invalid type hints definitions and usages

'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types
**kwargs,
):
"""Double taps on an element."""
try:
element = self.element(locator, condition=condition, **kwargs)
action = ActionHelpers()
action.double_tap(element).perform()
except Exception as e:
print(f"Error during double tap action: {e}")

def long_press(self):
pass
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ def __init__(self, driver):
super().__init__(driver)

def click_on_text_link(self):
self.click(locator = Common.text_link)
self.click(locator = Common.text_link)

def tap_on_text_link(self):
self.tap(locator = Common.text_link)
15 changes: 15 additions & 0 deletions tests/test_p1/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from screens.main_screen.main_screen import MainScreen


class TestClick:
@pytest.fixture(autouse=True)
def setup(self, driver) -> None:
"""Setup common objects for tests after address is set."""
self.main_screen = MainScreen(driver)

def test_click(self, setup):
self.main_screen.click_on_text_link()

def test_tap(self, setup):
self.main_screen.tap_on_text_link()
7 changes: 0 additions & 7 deletions tests/test_p1/test_p1.py

This file was deleted.

Loading