@@ -24,6 +24,7 @@ var Binary = require('./binary').Binary,
24
24
webdriver = require ( '..' ) ,
25
25
executors = require ( '../executors' ) ,
26
26
httpUtil = require ( '../http/util' ) ,
27
+ io = require ( '../io' ) ,
27
28
net = require ( '../net' ) ,
28
29
portprober = require ( '../net/portprober' ) ;
29
30
@@ -156,6 +157,10 @@ var Driver = function(opt_config, opt_flow) {
156
157
caps . set ( 'firefox_binary' , null ) ;
157
158
caps . set ( 'firefox_profile' , null ) ;
158
159
160
+ /** @private {?string} */
161
+ this . profilePath_ = null ;
162
+
163
+ var self = this ;
159
164
var serverUrl = portprober . findFreePort ( ) . then ( function ( port ) {
160
165
var prepareProfile ;
161
166
if ( typeof profile === 'string' ) {
@@ -170,6 +175,7 @@ var Driver = function(opt_config, opt_flow) {
170
175
}
171
176
172
177
return prepareProfile . then ( function ( dir ) {
178
+ self . profilePath_ = dir ;
173
179
return binary . launch ( dir ) ;
174
180
} ) . then ( function ( ) {
175
181
var serverUrl = url . format ( {
@@ -193,6 +199,19 @@ var Driver = function(opt_config, opt_flow) {
193
199
util . inherits ( Driver , webdriver . WebDriver ) ;
194
200
195
201
202
+ /** @override */
203
+ Driver . prototype . quit = function ( ) {
204
+ return this . call ( function ( ) {
205
+ var self = this ;
206
+ return Driver . super_ . prototype . quit . call ( this ) . thenFinally ( function ( ) {
207
+ if ( self . profilePath_ ) {
208
+ return io . rmDir ( self . profilePath_ ) ;
209
+ }
210
+ } ) ;
211
+ } , this ) ;
212
+ } ;
213
+
214
+
196
215
// PUBLIC API
197
216
198
217
0 commit comments