Масштабирование карты на Android с помощью клиента Appium Python - PullRequest
0 голосов
/ 07 мая 2018

Я работаю над автоматическим тестированием приложения для 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 v1.8.0, Python 3.5, Python-Appium v0.26 и эмулятор под управлением Android 6.0.

[1] Масштабировать действие в Android с помощью appium-python-client

...