Skip to content

Suspicious functionality change in driver.swipe() and driver.scroll() duration argument #743

@jatalahd

Description

@jatalahd

The problem

Before the ActionChains were used (Appium 1.20.x, Python Client 1.x.x) as they are now written in action_helpers.py we had used the following method to swipe the screen open from screen lock state:

driver.swipe(x1, y1, x2, y2, duration=3000)

This gave a slow swipe that took 3 seconds to move from x1,y1 to x2,y2.

When updating to Appium 2.0 and the latest Appium Python Client, the swipe did not work properly anymore.

If I understand the code properly in action_helpers.py, the functionality now uses the duration argument as pause between the move from x1,y1 to x2,y2:

actions.w3c_actions.pointer_action.pause(duration / 1000)

But the actual swipe action is very fast, in my case with a three second pause before the actual fast swipe action!

To get the swipe to work as before, I made a copy of the swipe method from action_helpers.py and changed like this:

def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
    actions = ActionChains(self)
    actions.w3c_actions = ActionBuilder(self, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"), duration=duration)
    actions.w3c_actions.pointer_action.move_to_location(start_x, start_y)
    actions.w3c_actions.pointer_action.pointer_down()
    actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
    actions.w3c_actions.pointer_action.release()
    actions.perform()

Notice that I have moved the duration parameter to the ActionBuilder constructor and removed the pause completely.

So I am proposing to implement the swipe() and scroll() like this and if someone requires an actual pause between the move, then I suggest adding an additional pause argument to the method signature.

Also I would like to see long_press(element: WebElement, timeout: int) to be added to action_helpers.py, where the pause would actually use the timeout value.

Thanks!

Environment

Appium version: 2.0.0Beta40
Appium Python Client version 2.6.0
OS version: Linux Ubuntu 20.04
Mobile platform: Android (real device)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions