9

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

我目前正在使用

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

但同样,这不会执行任何缩放。而是向下滚动列表。有人知道这里出了什么问题。

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 {}
4

1 回答 1

4

MultiAction 尝试看起来不错,但是在我手机的原生相机应用程序上进行了一些测试后,我能够通过在 moveTo() 之后添加 500 毫秒 wait() 来获得一个不错的缩放手势:

# 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() 可用于控制手势的时间:https ://github.com/appium/appium/blob/master/docs/en/writing-running-appium/触摸动作.md

我在我的相机应用程序中将xxand设置yy为屏幕中间:

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

请记住,坐标永远不应超出设备屏幕边界,因此如果您想让它成为可重用的函数,检查屏幕边界可能很有用。

在自动化 Chrome 时,我也无法使用 MultiAction 手势(即使更改为 NATIVE_APP 上下文。手势没有效果。)因此可能不支持在 WebView 场景上使用 MultiAction。

于 2016-07-27T13:21:37.173 回答