2017-02-10 4 views
0

Ich habe eine Android App, die ich versuche zu testen mit culebra. Der Code ist unten gezeigt.Drücken von Schaltflächen durch "Text" auf Android App mit Culebra

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

Wenn ich laufe das Skript als

$ python test_culebra.py

ich folgende Fehlermeldung erhalten.

[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 

Es ist das Installieren und Laden der App. Es ist jedoch nicht in der Lage, die Taste mit dem Text PRO', FIE , DIA` usw. zu finden.

Was mache ich hier falsch.

+0

Es scheint, dass 'b.getXY()' die Koordinaten der Ansicht nicht zurückgibt. Überprüfen Sie, ob "b" enthält, was Sie erwarten. –

+0

Verwenden Sie 'culebra' oder' culebra -G auch, um die Berührung für einen Fall zu generieren, und dann können Sie es in eine Schleife verwandeln. Auf diese Weise haben Sie die korrekte Syntax. –

+0

@DiegoTorresMilano - wie verwende ich culbera -G innerhalb des Python-Skripts? – liv2hak

Antwort

1

Run

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

Sie ein Fenster, das Ihrem Gerät sehen werden, ähnlich wie

enter image description here

dann klicken Sie auf die Tasten und culebra (Ich bin ApiDemos hier läuft) erzeugt

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) 

, wo Sie dann ein Mann drehen ually in

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

oder sogar

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

dies den Bildschirm wird unter der Annahme, ändert sich nicht, wenn Sie Ihre Schaltflächen klicken, wenn es Sie wieder anrufen vc.dump() benötigt.

Dann können Sie kopieren und in Ihr ursprüngliches Skript einfügen.

+0

Ich kann Pillow auf Python 2.7 nicht installieren http://StackOverflow.com/Questions/42192775/Installation-Pillow-on-Python-2-7 – liv2hak

Verwandte Themen