使用Appium Python客户端在Android上缩放地图

时间:2018-05-07 12:00:42

标签: android python appium zoom python-appium

我正在为具有地图屏幕的Android应用程序进行自动化测试。在那个屏幕上,我想放大和缩小。我无法让它发挥作用。是的,我已经阅读了这里的回复[1]并且它不起作用。以下是我的尝试。

继续在地图上工作:

# Move south on the map
move_south = TouchAction(driver)
move_south.press(x=map_center_x, y=map_center_y).wait(100) \
    .move_to(x=map_center_x, y=map_center_y-200).wait(100).release()
move_south.perform()

# Move north on the map
move_north = TouchAction(driver)
move_north.press(x=map_center_x, y=map_center_y).wait(100) \
    .move_to(x=map_center_x, y=map_center_y+200).wait(100).release()
move_north.perform()

放大(使用两根手指)没有做任何事情(没有错误,没有地图移动):

# Zoom in - two fingers
move_south = TouchAction(driver)
move_south.press(x=map_center_x, y=map_center_y).wait(100) \
    .move_to(x=map_center_x, y=map_center_y-200).wait(100).release()
move_north = TouchAction(driver)
move_north.press(x=map_center_x, y=map_center_y).wait(100) \
    .move_to(x=map_center_x, y=map_center_y+200).wait(100).release()
zoom_in_2_fingers = MultiAction(driver)
zoom_in_2_fingers.add(move_south)
zoom_in_2_fingers.add(move_north)
zoom_in_2_fingers.perform()

以下是Appium日志:

[HTTP] --> POST /wd/hub/session/67ddf81f-2b58-4022-9744-d541694e4365/touch/multi/perform
[HTTP] {"sessionId":"67ddf81f-2b58-4022-9744-d541694e4365","actions":[[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":500}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}],[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":900}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}]]}
[debug] [W3C] Calling AppiumDriver.performMultiAction() with args: [[[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":500}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}],[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":900}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}]],null,"67ddf81f-2b58-4022-9744-d541694e4365",null,"67ddf81f-2b58-4022-9744-d541694e4365"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"performMultiPointerGesture","params":{"actions":[[{"action":"press","time":0.005,"touch":{"x":384,"y":700}},{"action":"wait","time":0.105,"touch":{"x":384,"y":700}},{"action":"moveTo","time":0.11,"touch":{"x":384,"y":500}},{"action":"wait","time":0.21,"touch":{"x":384,"y":500}}],[{"action":"press","time":0.005,"touch":{"x":384,"y":700}},{"action":"wait","time":0.105,"touch":{"x":384,"y":700}},{"action":"moveTo","time":0.11,"touch":{"x":384,"y":900}},{"action":"wait","time":0.21,"touch":{"x":384,"y":900}}]]}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"performMultiPointerGesture","params":{"actions":[[{"action":"press","time":0.005,"touch":{"x":384,"y":700}},{"action":"wait","time":0.105,"touch":{"x":384,"y":700}},{"action":"moveTo","time":0.11,"touch":{"x":384,"y":500}},{"action":"wait","time":0.21,"touch":{"x":384,"y":500}}],[{"action":"press","time":0.005,"touch":{"x":384,"y":700}},{"action":"wait","time":0.105,"touch":{"x":384,"y":700}},{"action":"moveTo","time":0.11,"touch":{"x":384,"y":900}},{"action":"wait","time":0.21,"touch":{"x":384,"y":900}}]]}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: performMultiPointerGesture
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK"}
[debug] [W3C] Responding to client with driver.performMultiAction() result: "OK"
[HTTP] <-- POST /wd/hub/session/67ddf81f-2b58-4022-9744-d541694e4365/touch/multi/perform 200 698 ms - 76
[HTTP]

缩小(使用两根手指)不会抛出错误,但地图会变成空白(?):

# Zoom out - two fingers
move_south = TouchAction(driver)
move_south.press(x=map_center_x, y=map_center_y+200).wait(100) \
    .move_to(x=map_center_x, y=map_center_y).wait(100).release()
move_north = TouchAction(driver)
move_north.press(x=map_center_x, y=map_center_y-200).wait(100) \
    .move_to(x=map_center_x, y=map_center_y).wait(100).release()
zoom_out_2_fingers = MultiAction(driver)
zoom_out_2_fingers.add(move_south)
zoom_out_2_fingers.add(move_north)
zoom_out_2_fingers.perform()

放大(使用单指手势,点击然后向下拖动)放大,但偏离中心(这很奇怪,因为无论我在模拟器上用鼠标重复此手势,都会发生缩放在地图上的中心点附近):

# Zoom in - one finger
zoom_in_1_finger = TouchAction(driver)
zoom_in_1_finger.press(x=map_center_x, y=map_center_y).wait(100).release()\
    .press(x=map_center_x, y=map_center_y).wait(100)\
    .move_to(x=map_center_x, y=map_center_y+200).wait(100).release()
zoom_in_1_finger.perform()

缩小(一根手指)实际上放大,再次偏离中心:

# Zoom out - one finger
zoom_out_1_finger = TouchAction(driver)
zoom_out_1_finger.press(x=map_center_x, y=map_center_y).wait(100).release()\
    .press(x=map_center_x, y=map_center_y).wait(100)\
    .move_to(x=map_center_x, y=map_center_y-200).wait(100).release()
zoom_out_1_finger.perform()

以下是此日志:

[HTTP] --> POST /wd/hub/session/67ddf81f-2b58-4022-9744-d541694e4365/touch/perform
[HTTP] {"sessionId":"67ddf81f-2b58-4022-9744-d541694e4365","actions":[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}},{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":500}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}]}
[debug] [W3C] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}},{"action":"press","options":{"x":384,"y":700}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":384,"y":500}},{"action":"wait","options":{"ms":100}},{"action":"release","options":{}}],"67ddf81f-2b58-4022-9744-d541694e4365"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][768,1184]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchDown using element? false x: 384, y: 700
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchUp","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchUp","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchUp
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][768,1184]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchUp using element? false x: 384, y: 700
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":384,"y":700}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][768,1184]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchDown using element? false x: 384, y: 700
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchMove","params":{"x":384,"y":500}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchMove","params":{"x":384,"y":500}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchMove
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][768,1184]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchMove using element? false x: 384, y: 500
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchUp","params":{"x":384,"y":500}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchUp","params":{"x":384,"y":500}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchUp
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][768,1184]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchUp using element? false x: 384, y: 500
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [W3C] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/67ddf81f-2b58-4022-9744-d541694e4365/touch/perform 200 334 ms - 76
[HTTP] 

有人能帮我理解发生了什么吗?

我正在使用Appium v​​1.8.0,Python 3.5,Python-Appium v​​0.26和运行Android 6.0的模拟器。

[1] Zoom action in android using appium-python-client

0 个答案:

没有答案