2017-02-10 17 views
0

culebra을 사용하여 테스트하려는 Android 앱이 있습니다. 코드는 아래와 같습니다.Culebra를 사용하여 Android 앱에서 '텍스트'로 버튼 누르기

'''reated on 2017-02-08 by Culebra v12.5.3 
         __ __ __ __ 
        /\/\/\/\ 
____________________/ __\/ __\/ __\/ __\_____________________________ 
___________________/ /__/ /__/ /__/ /________________________________ 
        |/\ /\ /\ /\ \___ 
        |/ \_/ \_/ \_/ \ 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.dtmilano.android.adb.adbclient import DOWN_AND_UP 

kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} 
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) 
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True} 
vc = ViewClient(device, serialno, **kwargs2) 

# Installs the Android package. Notice that this method returns a boolean, so you can test 
# to see if the installation worked. 
vc.installPackage('Abc App.Android.Abc App.Android-Signed.apk') 


# sets a variable with the package's internal name 
package = 'Abc App.Android.Abc App.Android' 

# sets a variable with the name of an Activity in the packag 
activity = 'md591ecfcc00ede54e89ae8714.MainActivity' 

# sets the name of the component to start 
runComponent = package + '/' + activity 

# Runs the component 
device.startActivity(component=runComponent) 

vc.sleep(5) 

#vc = ViewClient(device) 
vc.dump() 

for bt in [ 'PRO', 'FIE', 'DIA']: 
    b = vc.findViewWithAttribute('text:mText', bt) 
    if b: 
     (x, y) = b.getXY() 
     print >>sys.stderr, "clicking b%s @ (%d,%d) ..." % (bt, x, y) 
     b.touch() 

    time.sleep(7) 


# Presses the Menu button 
# device.press('KEYCODE_MENU', DOWN_AND_UP) 

# Writes the screenshot to a file (you can use a plain filename or use these placeholders) 
vc.writeImageToFile('/tmp/${serialno}-${focusedwindowname}-${timestamp}.png', 'PNG') 

나는

$ python test_culebra.py

나는 다음과 같은 오류로 위의 스크립트를 실행합니다.

[100%] /data/local/tmp/AbcApp.Android.AbcApp.Android-Signed.apk 
     pkg: /data/local/tmp/AbcApp.Android.AbcApp.Android-Signed.apk 
Success 
Traceback (most recent call last): 
    File "monkey_runner_culebra.py", line 53, in <module> 
    print >>sys.stderr, "clicking b%s @ (%d,%d) ..." % (bt, x, y) 
NameError: name 'x' is not defined 

앱을 설치하고로드하는 중입니다. 그러나 텍스트가있는 PRO', FIE , DIA 등의 버튼을 찾을 수 없습니다.

여기서 잘못된 것은 무엇입니까?

+0

'b.getXY()'가 View의 좌표를 반환하지 않는 것 같습니다. 'b'에 당신이 기대하는 것을 포함하고 있는지 확인하십시오. –

+0

또한 'culebra'또는 'culebra -G'를 사용하여 하나의 케이스에 대한 터치를 생성 한 다음 루프로 바꿀 수 있습니다. 그렇게하면 올바른 구문을 사용할 수 있습니다. –

+0

@DiegoTorresMilano - python 스크립트에서 culbera -G를 어떻게 사용합니까? – liv2hak

답변

1

당신은 당신이 (내가 여기에 ApiDemos에 실행 해요) 버튼을 클릭 훨씬

enter image description here

같은 장치를 나타내는 창을 볼 culebra 있습니다

culebra -Gu -o myscript.py --scale=0.5 

실행 생성

vc.dump(window=-1) 
vc.findViewWithTextOrRaise(u'NORMAL').touch() 
vc.sleep(_s) 
vc.dump(window=-1) 
vc.findViewWithTextOrRaise(u'SMALL').touch() 
vc.sleep(_s) 
vc.dump(window=-1) 
vc.findViewWithTextOrRaise(u'OFF').touch() 
vc.sleep(_s) 
vc.dump(window=-1) 

부를 따로

for t in ['NORMAL', 'SMALL', 'OFF']: 
    b = vc.findViewWithTextOrRaise(t) 
    print >> sys.stderr, "clicking", b, "@", b.getXY() 
    b.touch() 

하거나 그것을 다시 vc.dump()를 호출해야 않는 경우 당신이 당신의 버튼을 클릭하면 변경되지 않습니다 화면을 가정하더라도

for t in ['NORMAL', 'SMALL', 'OFF']: 
    vc.findViewWithTextOrRaise(t).touch() 

로 설정합니다.

그런 다음 원본 스크립트로 복사하여 붙여 넣을 수 있습니다.

+0

python 2.7에 베개를 설치할 수 없습니다. http://stackoverflow.com/questions/42192775/installing-pillow-on-python-2-7 – liv2hak