@@ -73,6 +73,7 @@ def _execute(self, args, **kwargs):
73
73
logging .debug ("$> %s" , ' ' .join (args ))
74
74
output = execute (args , ** kwargs )
75
75
logging .debug (output )
76
+ return output
76
77
77
78
def start_emulator (self , avd_name , no_window = False ):
78
79
'''
@@ -81,21 +82,30 @@ def start_emulator(self, avd_name, no_window=False):
81
82
`avd_name` Identifier of the Android Virtual Device, for valid values on your machine run "$ANDROID_HOME/tools/android list avd|grep Name`
82
83
`no_window` Set to True to start the emulator without GUI, useful for headless environments.
83
84
'''
84
- cmd = [self ._emulator , '-avd' , avd_name ]
85
+ args = [self ._emulator , '-avd' , avd_name ]
85
86
86
87
if no_window :
87
- cmd .append ('-no-window' )
88
+ args .append ('-no-window' )
89
+
90
+ logging .debug ("$> %s" , ' ' .join (args ))
88
91
89
- self ._emulator_proc = subprocess .Popen (cmd )
92
+ self ._emulator_proc = subprocess .Popen (args )
90
93
91
94
def stop_emulator (self ):
92
95
'''
93
96
Halts a previously started Android Emulator.
94
97
'''
98
+
99
+ if not hasattr (self , '_emulator_proc' ):
100
+ logging .warn ("Could not stop Android Emulator: It was not started." )
101
+ return
102
+
95
103
self ._emulator_proc .terminate ()
96
104
self ._emulator_proc .kill ()
97
105
self ._emulator_proc .wait ()
98
106
107
+ self ._emulator_proc = None
108
+
99
109
def set_package_name (self , package_name ):
100
110
self ._package_name = package_name
101
111
@@ -109,10 +119,16 @@ def install_apk(self, test_apk_path, app_apk_path):
109
119
`test_apk_path` Path to the Test.apk, usually at 'features/support/Test.apk'
110
120
`app_apk_path` Path the the application you want to test
111
121
'''
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 ])
116
132
117
133
def wait_for_device (self ):
118
134
'''
0 commit comments