Skip to content

Commit 7030d91

Browse files
committed
fix: ios swipe is done by a script instead of driver.swipe()
1 parent 913bbd1 commit 7030d91

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

optics_framework/engines/drivers/appium.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,16 @@ def swipe(
630630
swipe_length: int,
631631
event_name: Optional[str] = None
632632
) -> None:
633+
633634
driver = self._require_driver()
635+
634636
x_coor = int(x_coor)
635637
y_coor = int(y_coor)
638+
swipe_length = int(swipe_length)
639+
636640
end_x: int = x_coor
637641
end_y: int = y_coor
642+
638643
if direction == "up":
639644
end_y = y_coor - swipe_length
640645
elif direction == "down":
@@ -646,17 +651,42 @@ def swipe(
646651
else:
647652
internal_logger.error(f"Unknown swipe direction: {direction}")
648653
return
654+
655+
platform = (
656+
self.capabilities.get(self.CAP_PLATFORM_NAME)
657+
or self.capabilities.get(self.CAP_APPIUM_PLATFORM_NAME)
658+
)
659+
649660
timestamp = self.event_sdk.get_current_time_for_events()
661+
650662
try:
651-
internal_logger.debug(
652-
f"Swiping from ({x_coor}, {y_coor}) to ({end_x}, {end_y})"
653-
)
654-
driver.swipe(x_coor, y_coor, end_x, end_y, 2000)
663+
# The standard driver.swipe() is flaky on iOS, so we're using a script for getting consistent results
664+
if str(platform).lower() == self.PLATFORM_IOS:
665+
internal_logger.debug(
666+
f"iOS swipe from ({x_coor},{y_coor}) to ({end_x},{end_y})"
667+
)
668+
driver.execute_script(
669+
"mobile: dragFromToForDuration",
670+
{
671+
"duration": 1.0,
672+
"fromX": x_coor,
673+
"fromY": y_coor,
674+
"toX": end_x,
675+
"toY": end_y,
676+
},
677+
)
678+
else:
679+
internal_logger.debug(
680+
f"Android swipe from ({x_coor},{y_coor}) to ({end_x},{end_y})"
681+
)
682+
driver.swipe(x_coor, y_coor, end_x, end_y, 1000)
683+
655684
if event_name:
656685
self.event_sdk.capture_event_with_time_input(event_name, timestamp)
686+
657687
except Exception as e:
658688
internal_logger.debug(
659-
f"Failed to swipe from ({x_coor}, {y_coor}) to ({end_x}, {end_y}): {e}"
689+
f"Failed swipe from ({x_coor},{y_coor}) to ({end_x},{end_y}): {e}"
660690
)
661691

662692

0 commit comments

Comments
 (0)