Skip to content

Commit caf3181

Browse files
Merge pull request #8 from dmberezovskyii/PPA-0005
PPA-0005: added ability to swipe and tap
2 parents 4ecd631 + bce102e commit caf3181

File tree

5 files changed

+73
-24
lines changed

5 files changed

+73
-24
lines changed

src/screens/base_screen.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import time
22
from typing import Tuple, Literal
33

4+
from selenium.webdriver.common.actions.action_builder import ActionBuilder
5+
from selenium.webdriver.common.actions.pointer_actions import PointerActions
6+
47
from screens.element_interactor import ElementInteractor
58
from appium.webdriver.extensions.action_helpers import ActionHelpers, ActionChains
69

@@ -21,22 +24,57 @@ def click(
2124
element.click()
2225

2326
def tap(self, locator, **kwargs):
24-
element = self.element(locator, condition="clickable", **kwargs)
25-
self.driver.tap()
26-
action_helpers = ActionHelpers()
27-
action_helpers.tap(element)
28-
29-
def tap_by_coordinates(self):
30-
pass
31-
32-
def swipe(self):
33-
pass
34-
35-
def type(self):
36-
pass
37-
38-
def double_tap(self):
39-
pass
27+
"""Taps on an element using ActionHelpers."""
28+
try:
29+
element = self.element(locator, condition="clickable", **kwargs)
30+
location = element.location
31+
size = element.size
32+
x = location["x"] + size["width"] // 2
33+
y = location["y"] + size["height"] // 2
34+
self.driver.tap([(x, y)])
35+
except Exception as e:
36+
print(f"Error during tap action: {e}")
37+
38+
def swipe(
39+
self,
40+
relative_start_x: float,
41+
relative_start_y: float,
42+
relative_end_x: float,
43+
relative_end_y: float,
44+
duration_ms: int = 200,
45+
) -> None:
46+
size = self.driver.get_window_size()
47+
width = size["width"]
48+
height = size["height"]
49+
start_x = int(width * relative_start_x)
50+
start_y = int(height * relative_start_y)
51+
end_x = int(width * relative_end_x)
52+
end_y = int(height * relative_end_y)
53+
self.driver.swipe(
54+
start_x=start_x,
55+
start_y=start_y,
56+
end_x=end_x,
57+
end_y=end_y,
58+
duration_ms=duration_ms,
59+
)
60+
61+
def type(self, locator: Locator, text: str):
62+
element = self.element(locator)
63+
element.send_keys(text)
64+
65+
def double_tap(
66+
self,
67+
locator: Locator,
68+
condition: Literal["clickable", "visible", "present"] = "clickable",
69+
**kwargs,
70+
):
71+
"""Double taps on an element."""
72+
try:
73+
element = self.element(locator, condition=condition, **kwargs)
74+
action = ActionHelpers()
75+
action.double_tap(element).perform()
76+
except Exception as e:
77+
print(f"Error during double tap action: {e}")
4078

4179
def long_press(self):
4280
pass
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ def __init__(self, driver):
88
super().__init__(driver)
99

1010
def click_on_text_link(self):
11-
self.click(locator = Common.text_link)
11+
self.click(locator = Common.text_link)
12+
13+
def tap_on_text_link(self):
14+
self.tap(locator = Common.text_link)

tests/test_p1/test_actions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from screens.main_screen.main_screen import MainScreen
3+
4+
5+
class TestClick:
6+
@pytest.fixture(autouse=True)
7+
def setup(self, driver) -> None:
8+
"""Setup common objects for tests after address is set."""
9+
self.main_screen = MainScreen(driver)
10+
11+
def test_click(self, setup):
12+
self.main_screen.click_on_text_link()
13+
14+
def test_tap(self, setup):
15+
self.main_screen.tap_on_text_link()

tests/test_p1/test_p1.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)