@@ -310,18 +310,28 @@ def testConnectToDeviceOrExit_environ(self):
310310 try :
311311 ViewClient .connectToDeviceOrExit (timeout = 1 , verbose = True )
312312 except RuntimeError , e :
313- self .assertTrue (re .search ("couldn't find device that matches 'ABC123'" , str (e )))
313+ msg = str (e )
314+ if re .search ('Is adb running on your computer?' , msg ):
315+ # This test required adb running
316+ self .fail (msg )
317+ elif not re .search ("couldn't find device that matches 'ABC123'" , msg ):
318+ self .fail (msg )
314319 except exceptions .SystemExit , e :
315320 self .assertEquals (3 , e .code )
316321 except Exception , e : #FIXME: java.lang.NullPointerException:
317- self .fail ('Serialno was not taken from environment: ' + str ( e ) )
322+ self .fail ('Serialno was not taken from environment: ' + msg )
318323
319324 def testConnectToDeviceOrExit_serialno (self ):
320325 sys .argv = ['' ]
321326 try :
322327 ViewClient .connectToDeviceOrExit (timeout = 1 , verbose = True , serialno = 'ABC123' )
323328 except RuntimeError , e :
324- self .assertTrue (re .search ("couldn't find device that matches 'ABC123'" , str (e )))
329+ msg = str (e )
330+ if re .search ('Is adb running on your computer?' , msg ):
331+ # This test required adb running
332+ self .fail (msg )
333+ elif not re .search ("couldn't find device that matches 'ABC123'" , msg ):
334+ self .fail (msg )
325335 except exceptions .SystemExit , e :
326336 self .assertEquals (3 , e .code )
327337 except Exception , e : #FIXME: java.lang.NullPointerException:
@@ -756,6 +766,35 @@ def testFindViewWithTextOrRaise_root(self):
756766 v5 = vc .findViewWithTextOrRaise ('5' , root = v3 )
757767 self .assertEqual ('v35' , v5 .getTag ())
758768
769+ def testFindViewWithTextOrRaise_root_disappearingView (self ):
770+ device = None
771+ root = View ({'text:mText' :'0' }, device )
772+ root .add (View ({'text:mText' :'1' }, device ))
773+ root .add (View ({'text:mText' :'2' }, device ))
774+ v3 = View ({'text:mText' :'3' }, device )
775+ root .add (v3 )
776+ v35 = View ({'text:mText' :'5' , 'getTag()' :'v35' }, device )
777+ v3 .add (v35 )
778+ v4 = View ({'text:mText' :'4' }, device )
779+ root .add (v4 )
780+ v45 = View ({'text:mText' :'5' , 'getTag()' :'v45' }, device )
781+ v4 .add (v45 )
782+ device = MockDevice ()
783+ vc = ViewClient (device , device .serialno , adb = TRUE , autodump = False )
784+ self .assertNotEquals (None , vc )
785+ vc .root = root
786+ v5 = vc .findViewWithTextOrRaise ('5' )
787+ self .assertEqual ('v35' , v5 .getTag ())
788+ v5 = vc .findViewWithTextOrRaise ('5' , root = v4 )
789+ self .assertEqual ('v45' , v5 .getTag ())
790+ v5 = vc .findViewWithTextOrRaise ('5' , root = v3 )
791+ self .assertEqual ('v35' , v5 .getTag ())
792+ # Then remove v4 and its children
793+ root .children .remove (v4 )
794+ #vc.dump()
795+ v4 = vc .findViewWithText ('4' )
796+ self .assertEqual (v4 , None , "v4 has not disappeared" )
797+
759798 def testFindViewWithTextOrRaise_rootNonExistent (self ):
760799 device = None
761800 root = View ({'text:mText' :'0' }, device )
0 commit comments