3030from com .dtmilano .android .concertina import Concertina
3131from com .dtmilano .android .viewclient import ViewClient
3232
33- __version__ = '15.3.0 '
33+ __version__ = '15.3.1 '
3434
3535import sys
3636import threading
@@ -586,6 +586,7 @@ def findTargets(self):
586586 self .printOperation (None , Operation .DUMP , window , dump )
587587 else :
588588 dump = []
589+ self .dump = dump
589590 # the root element cannot be deleted from Treeview once added.
590591 # We have no option but to recreate it
591592 self .viewTree = ViewTree (self .sideFrame )
@@ -1440,9 +1441,12 @@ def concertinaLoopCallback(self, dontinteract=False):
14401441 needToSleep = False
14411442 if not dontinteract :
14421443 if DEBUG_CONCERTINA :
1443- print >> sys .stderr , "CONCERTINA: should select one of these targets:"
1444- for v in self .targetViews :
1445- print >> sys .stderr , " " , unicode (v .__tinyStr__ ()), v .getContentDescription ()
1444+ if len (self .targetViews ) > 0 :
1445+ print >> sys .stderr , "CONCERTINA: should select one of these {} targets:" .format (len (self .targetViews ))
1446+ for v in self .targetViews :
1447+ print >> sys .stderr , " " , unicode (v .__tinyStr__ ()), v .getContentDescription ()
1448+ else :
1449+ print >> sys .stderr , "CONCERTINA: empty target list, nothing to select"
14461450 rand = random .random ()
14471451 if DEBUG_CONCERTINA :
14481452 print >> sys .stderr , "CONCERTINA: random=%f" % rand
@@ -1453,9 +1457,8 @@ def concertinaLoopCallback(self, dontinteract=False):
14531457 k = numpy .random .choice (systemKeys ['keys' ], 1 , p = systemKeys ['probabilities' ])[0 ]
14541458 if DEBUG_CONCERTINA :
14551459 print >> sys .stderr , "CONCERTINA: system key=" + k
1456- # DEBUG ONLY!
1457- # print >> sys.stderr, "Not sending key event"
14581460 self .command (k )
1461+ self .sleepAndRefreshScreen ()
14591462 else :
14601463 # Right now we have p[systemKeys] + p[views] = 1
14611464 # Act on views
@@ -1602,33 +1605,46 @@ def concertinaLoopCallback(self, dontinteract=False):
16021605 if DEBUG_CONCERTINA :
16031606 print >> sys .stderr , "CONCERTINA: touchOtherViews probability == 0"
16041607 if needToSleep :
1605- self .printOperation (None , Operation .SLEEP , Operation .DEFAULT )
1606- if DEBUG_CONCERTINA :
1607- print >> sys .stderr , "CONCERTINA: waiting 5 secs"
1608- time .sleep (5 )
1609- if DEBUG_CONCERTINA :
1610- print >> sys .stderr , "CONCERTINA: updating window"
1611- self .takeScreenshotAndShowItOnWindow ()
1608+ self .sleepAndRefreshScreen ()
16121609 else :
16131610 # _tvli
16141611 if DEBUG_CONCERTINA :
16151612 print >> sys .stderr , "CONCERTINA: Filter results in empty target list"
16161613 else :
1617- # Let's wait to see if some View appear
1618- needToSleep = True
1619- self .noTargetViewsCount += 1
1620- if DEBUG_CONCERTINA :
1621- print >> sys .stderr , "CONCERTINA: No target views" , self .noTargetViewsCount
1622- if self .noTargetViewsCount >= self .concertinaConfig ['limits' ]['maxNoTargetViewsIterations' ]:
1623- print >> sys .stderr , "CONCERTINA: Cannot detect target Views after {} iterations" .format (
1624- self .noTargetViewsCount )
1625- sys .exit (1 )
1614+ # There are many cases where the Views are not touchable/selectable/focusable/etc so they don't
1615+ # appear in targetViews, like popups, menus, lisviews, etc. so let's give them a change
1616+ if self .dump and probabilities ['views' ] > 0 :
1617+ target = random .choice (self .dump )
1618+ if DEBUG_CONCERTINA :
1619+ print >> sys .stderr , "CONCERTINA: touching non-target view {}" .format (target )
1620+ self .touchView (target )
1621+ self .sleepAndRefreshScreen ()
1622+ needToSleep = True
1623+ else :
1624+ # Let's wait to see if some View appear
1625+ needToSleep = True
1626+ self .noTargetViewsCount += 1
1627+ if DEBUG_CONCERTINA :
1628+ print >> sys .stderr , "CONCERTINA: No target views" , self .noTargetViewsCount
1629+ if self .noTargetViewsCount >= self .concertinaConfig ['limits' ]['maxNoTargetViewsIterations' ]:
1630+ print >> sys .stderr , "CONCERTINA: Cannot detect target Views after {} iterations" .format (
1631+ self .noTargetViewsCount )
1632+ sys .exit (1 )
16261633 if self .iterations >= self .concertinaConfig ['limits' ]['iterations' ]:
16271634 print >> sys .stderr , "CONCERTINA: Maximum number of iterations reached"
16281635 sys .exit (0 )
16291636 self .iterations += 1
16301637 self .window .after (5000 if dontinteract or needToSleep else 0 , self .concertinaLoopCallback )
16311638
1639+ def sleepAndRefreshScreen (self ):
1640+ self .printOperation (None , Operation .SLEEP , Operation .DEFAULT )
1641+ if DEBUG_CONCERTINA :
1642+ print >> sys .stderr , "CONCERTINA: waiting 5 secs"
1643+ time .sleep (5 )
1644+ if DEBUG_CONCERTINA :
1645+ print >> sys .stderr , "CONCERTINA: updating window"
1646+ self .takeScreenshotAndShowItOnWindow ()
1647+
16321648 def sleep (self , s ):
16331649 time .sleep (s )
16341650 self .printOperation (None , Operation .SLEEP , s )
0 commit comments