Zoom action in android using appium-python-client

人盡茶涼 提交于 2019-12-05 02:48:40

The MultiAction attempt looks good, but after testing a bit on my phone's native camera app, I was able to get a nice zoom gesture by adding 500ms wait() after the moveTo():

# Zoom
action1.long_press(x=xx, y=yy).move_to(x=0, y=50).wait(500).release()
action2.long_press(x=xx, y=yy).move_to(x=0, y=-50).wait(500).release()
m_action.add(action1, action2)

# Pinch
action3.long_press(x=xx, y=yy-50).move_to(x=0, y=50).wait(500).release()
action4.long_press(x=xx, y=yy+50).move_to(x=0, y=-50).wait(500).release()
m_action2.add(action3, action4)

m_action.perform()
m_action2.perform()

This resulted in a nice and slow zoom to the camera app. Without the wait() the gestures were too quick and didn't really do much. It is mentioned at Appium's documentation at Github, that wait() can be used to control the timing of a gesture: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md

I set the xx and yy to the middle of the screen in my camera app with:

xx = self.driver.get_window_size()['width']/2
yy = self.driver.get_window_size()['height']/2

Please remember that coordinates should never go out of device screen bounds, so checks for screen borders may be useful, if you want to make this into a re-usable function.

I also couldn't use the MultiAction gestures when automating Chrome (not even when changing to NATIVE_APP context. The gestures had no effect.) so it's possible that using MultiActions on WebView scenarios isn't supported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!