使用appium-python-client在android中缩放动作 [英] Zoom action in android using appium-python-client

查看:128
本文介绍了使用appium-python-client在android中缩放动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何通过appium python客户端缩放android中的元素吗?

Does anybody know how to zoom an element in android via appium python client?

我当前正在使用

self.driver.zoom(self.element, percent)但这给出了错误

self.driver.zoom(self.element, percent)
File "/usr/local/lib/python2.7/site-packages/appium/webdriver/webdriver.py", line 308, in zoom
self.execute_script('mobile: pinchOpen', opts)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 461, in execute_script
{'script': script, 'args':converted_args})['value']
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
WebDriverException: Message: Method has not yet been implemented

我也尝试过MultiAction.

loc = self.element.location
print loc
xx, yy = loc["x"], loc["y"]
xx=700
action1 = TouchAction(self.driver)
action1.long_press(x=xx, y=yy).move_to(x=0, y=1000).release()
action2 = TouchAction(self.driver)
action2.long_press(x=xx, y=yy).move_to(x=0, y=-1000).release()
m_action = MultiAction(self.driver)
m_action.add(action1, action2)
m_action.perform()

但这又不执行任何缩放操作,而是向下滚动列表.是否有人对这里的问题有任何了解

But again this does not perform any zoom.Instead it scrolls down the list.Does anybody have any idea about what's wrong here.

Appium Logs

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getLocation","params":{"elementId":"83"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getLocation
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"x":0,"y":1225}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.getLocation() result: {"x":0,"y":1225}
[HTTP] <-- GET /wd/hub/session/c1a4d17f-0dc6-4445-bfad-776ec65bddb5/element/83/location 200 26 ms - 88 
[HTTP] --> POST /wd/hub/session/c1a4d17f-0dc6-4445-bfad-776ec65bddb5/touch/multi/perform {"sessionId":"c1a4d17f-0dc6-4445-bfad-776ec65bddb5","actions":[[{"action":"longPress","options":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","options":{"y":1000,"x":0}},{"action":"release","options":{}}],[{"action":"longPress","options":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","options":{"y":-1000,"x":0}},{"action":"release","options":{}}]]}
[MJSONWP] Calling AppiumDriver.performMultiAction() with args: [[[{"action":"longPress","o...
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"performMultiPointerGesture","params":{"actions":[[{"action":"longPress","time":0.005,"touch":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","time":0.01,"touch":{"y":2225,"x":700}}],[{"action":"longPress","time":0.005,"touch":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","time":0.01,"touch":{"y":225,"x":700}}]]}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"performMultiPointerGesture","params":{"actions":[[{"action":"longPress","time":0.005,"touch":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","time":0.01,"touch":{"y":2225,"x":700}}],[{"action":"longPress","time":0.005,"touch":{"y":1225,"x":700,"duration":1000}},{"action":"moveTo","time":0.01,"touch":{"y":225,"x":700}}]]}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: performMultiPointerGesture
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.performMultiAction() result: "OK"
[HTTP] <-- POST /wd/hub/session/c1a4d17f-0dc6-4445-bfad-776ec65bddb5/touch/multi/perform 200 133 ms - 76 
[HTTP] --> DELETE /wd/hub/session/c1a4d17f-0dc6-4445-bfad-776ec65bddb5 {}

推荐答案

MultiAction尝试看起来不错,但是在手机的本机摄像头应用程序上进行了一些测试之后,我通过添加500ms wait()获得了不错的缩放手势.在moveTo()之后:

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()

这导致了对相机应用的良好且缓慢的缩放.没有wait()的手势太快了,实际上并没有做太多事情.在Github的Appium文档中提到了wait()可用于控制手势的时间:

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

我将xxyy设置为以下应用程序在我的相机应用程序的屏幕中间:

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.

自动执行Chrome时,我也无法使用MultiAction手势(即使更改为NATIVE_APP上下文也不会.手势不起作用.)因此,可能不支持在WebView场景中使用MultiAction.

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.

这篇关于使用appium-python-client在android中缩放动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆