dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.63k stars 347 forks source link

dump is not showing correct X,Y in Power Options #29

Closed levrado closed 11 years ago

levrado commented 11 years ago

Hi,

i'm trying to toggle airplane mode so i simulate a long press on power button to enter the device options menu. then i search for the "airplane mode" query to press it but it pressing the wrong x,y

i did a dump -c on the window and saw that there is offset of 200px in the y axis i tried it on galaxy s2 & s3 version 4.1.2

dtmilano commented 11 years ago

Please, re-test and close if appropriate

levrado commented 11 years ago

It's closer now but still not the correct coordiantes, the offset in the y axis is now 100px BTW it works if i do it like this:

    device.press("KEYCODE_POWER", 'down')
    vc = ViewClient(device, serialno)
    x = int(vc.findViewWithText("Flight mode").getX())
    y = int(vc.findViewWithText("Flight mode").getY())
    device.touch(x,y,"DOWN_AND_UP")
    vc.dump()
    x = int(vc.findViewWithText("OK").getX())
    y = int(vc.findViewWithText("OK").getY())
    device.touch(x,y,"DOWN_AND_UP")
dtmilano commented 11 years ago

I have tested the patch on the emulator and 4.2.2 devices and worked. Unfortunately, the problem is due to a bug in uiautomator in version 4.1.2. I haven't had time yet to analyze it deeply, but these screenshots clearly shows the issue: device-2013-06-13-175632 device-2013-06-13-173733 They have been obtained running the same script autogenerated by culebra and slightly modified after:

#! /usr/local/bin/shebang monkeyrunner -plugin $AVC_HOME/bin/androidviewclient-$AVC_VERSION.jar @!
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013  Diego Torres Milano
Created on 2013-06-13 by Culebra v0.9.11

                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''

import re
import sys
import os

from com.dtmilano.android.viewclient import ViewClient

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

kwargs1 = {'verbose': True, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
vc = ViewClient(device, serialno, **kwargs2)
vc.dump(window='-1')

# class=android.widget.TextView text="Airplane mode"
v = vc.findViewWithTextOrRaise('Airplane mode')
print "center=", v.getCenter()