Skip to content

Commit 0d43cca

Browse files
Alvaro LasernaAlvaro Laserna
authored andcommitted
fix actions bug for press_hold and swipe actions
1 parent cd03295 commit 0d43cca

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

tests/selenium_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from selenium.webdriver.chrome.options import Options
44

5+
from testui.elements.testui_element import e
56
from testui.support import logger
67
from testui.support.appium_driver import NewDriver
78
from testui.support.testui_driver import TestUIDriver
@@ -37,6 +38,10 @@ def test_template_matching(self, selenium_driver: TestUIDriver):
3738
selenium_driver.find_image_match(
3839
image_compare, 0.1, True, image_match=image_result
3940
)
41+
e(selenium_driver, 'xpath', '//h3[contains(text(), "Image Recognition:")]')\
42+
.wait_until_visible().press_hold_for()
43+
e(selenium_driver, 'xpath', '//h3[contains(text(), "Image Recognition:")]')\
44+
.swipe(start_x=50, start_y=50, end_x=100, end_y=100)
4045
selenium_driver.raise_errors()
4146

4247
@pytest.mark.signup

testui/elements/testui_element.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def press_hold_for(self, milliseconds=1000):
512512
err = None
513513
while time.time() < start + timeout:
514514
try:
515-
actions = self.driver.actions()
515+
actions = self.testui_driver.actions()
516516
actions.w3c_actions.pointer_action.click_and_hold(self.get_element())
517517
actions.w3c_actions.pointer_action.pause(milliseconds // 1000)
518518
actions.w3c_actions.pointer_action.release()
@@ -724,33 +724,27 @@ def swipe(
724724
end_x = location2.x
725725
if end_y is None:
726726
end_y = location2.y
727-
728-
actions = self.driver.actions()
729-
actions.w3c_actions.pointer_action.move_to_location(x=start_x, y=start_y)
730-
actions.w3c_actions.pointer_action.pointer_down()
731-
if duration:
732-
actions.w3c_actions.pointer_action.pause(duration)
733-
actions.w3c_actions.pointer_action.move_to_location(x=end_x, y=end_y)
734-
actions.w3c_actions.pointer_action.release()
735-
actions.perform()
736727
else:
737728
if end_x is None:
738729
end_x = location.x
739730
if end_y is None:
740731
end_y = location.y
741-
self.driver.swipe(
742-
start_y=start_y,
743-
start_x=start_x,
744-
end_y=end_y,
745-
end_x=end_x,
746-
duration=duration,
747-
)
732+
733+
actions = self.testui_driver.actions()
734+
actions.w3c_actions.pointer_action.move_to_location(x=start_x, y=start_y)
735+
actions.w3c_actions.pointer_action.pointer_down()
736+
if duration:
737+
actions.w3c_actions.pointer_action.pause(duration)
738+
actions.w3c_actions.pointer_action.move_to_location(x=end_x, y=end_y)
739+
actions.w3c_actions.pointer_action.release()
740+
actions.perform()
748741
return self
749742
except Exception as error:
750743
err = error
751744
return self.__show_error(
752-
f"{logger.bcolors.FAIL}{err} {self.device_name}: Element not found "
753-
f'with the following locator: "{self.locator_type}:{self.locator}" '
745+
f"{logger.bcolors.FAIL}{err} {self.device_name}: Error swiping "
746+
f'with the following locator: "{self.locator_type}:{self.locator}", '
747+
f'with the following coordinates "{start_x}", "{start_y}", "{end_x}", "{end_y}"'
754748
f"after {time.time() - start}s {logger.bcolors.ENDC}"
755749
)
756750

0 commit comments

Comments
 (0)