diff --git a/lib/runner.js b/lib/runner.js index 0f4ca4904..c5daec861 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -200,6 +200,14 @@ Runner.prototype.run = function() { this.setTestPreparer(this.config_.onPrepare); + var gracefulShutdown = function(driver) { + return driver.getSession().then(function(session_) { + if (session_) { + return driver.quit(); + } + }); + }; + // 1) Setup environment //noinspection JSValidateTypes return this.driverprovider_.setupEnv().then(function() { @@ -254,6 +262,8 @@ Runner.prototype.run = function() { var passed = testResult.failedCount === 0; var exitCode = passed ? 0 : 1; return self.exit_(exitCode); + }).fin(function() { + return gracefulShutdown(driver); }); };