@@ -73,6 +73,7 @@ def _execute(self, args, **kwargs):
7373 logging .debug ("$> %s" , ' ' .join (args ))
7474 output = execute (args , ** kwargs )
7575 logging .debug (output )
76+ return output
7677
7778 def start_emulator (self , avd_name , no_window = False ):
7879 '''
@@ -81,21 +82,30 @@ def start_emulator(self, avd_name, no_window=False):
8182 `avd_name` Identifier of the Android Virtual Device, for valid values on your machine run "$ANDROID_HOME/tools/android list avd|grep Name`
8283 `no_window` Set to True to start the emulator without GUI, useful for headless environments.
8384 '''
84- cmd = [self ._emulator , '-avd' , avd_name ]
85+ args = [self ._emulator , '-avd' , avd_name ]
8586
8687 if no_window :
87- cmd .append ('-no-window' )
88+ args .append ('-no-window' )
89+
90+ logging .debug ("$> %s" , ' ' .join (args ))
8891
89- self ._emulator_proc = subprocess .Popen (cmd )
92+ self ._emulator_proc = subprocess .Popen (args )
9093
9194 def stop_emulator (self ):
9295 '''
9396 Halts a previously started Android Emulator.
9497 '''
98+
99+ if not hasattr (self , '_emulator_proc' ):
100+ logging .warn ("Could not stop Android Emulator: It was not started." )
101+ return
102+
95103 self ._emulator_proc .terminate ()
96104 self ._emulator_proc .kill ()
97105 self ._emulator_proc .wait ()
98106
107+ self ._emulator_proc = None
108+
99109 def set_package_name (self , package_name ):
100110 self ._package_name = package_name
101111
@@ -109,10 +119,16 @@ def install_apk(self, test_apk_path, app_apk_path):
109119 `test_apk_path` Path to the Test.apk, usually at 'features/support/Test.apk'
110120 `app_apk_path` Path the the application you want to test
111121 '''
112- self ._execute ([self ._adb , "uninstall" , "%s.test" % self ._package_name ])
113- self ._execute ([self ._adb , "uninstall" , self ._package_name ])
114- self ._execute ([self ._adb , "install" , "-r" , test_apk_path ])
115- self ._execute ([self ._adb , "install" , "-r" , app_apk_path ])
122+
123+ def execute_and_output_does_not_contain_error (* args ):
124+ output = self ._execute (* args )
125+ assert 'Error' not in output , output
126+ return output
127+
128+ execute_and_output_does_not_contain_error ([self ._adb , "uninstall" , "%s.test" % self ._package_name ])
129+ execute_and_output_does_not_contain_error ([self ._adb , "uninstall" , self ._package_name ])
130+ execute_and_output_does_not_contain_error ([self ._adb , "install" , "-r" , test_apk_path ])
131+ execute_and_output_does_not_contain_error ([self ._adb , "install" , "-r" , app_apk_path ])
116132
117133 def wait_for_device (self ):
118134 '''
0 commit comments