Skip to content

Commit

Permalink
feat(protractor): Add protractor.prototype.restart
Browse files Browse the repository at this point in the history
  • Loading branch information
avdd authored and hankduan committed Nov 9, 2015
1 parent 4aa5127 commit 97e6703
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ Protractor.prototype.getProcessedConfig = null;
*/
Protractor.prototype.forkNewDriverInstance = null;

/**
* Restart the browser instance.
*
* Set by the runner.
*/
Protractor.prototype.restart = null;

/**
* Instead of using a single root element, search through all angular apps
Expand Down
18 changes: 11 additions & 7 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ Runner.prototype.createBrowser = function(plugins) {
}
return newBrowser;
};

browser_.restart = function() {
// Note: because tests are not paused at this point, any async
// calls here are not guaranteed to complete before the tests resume.
self.driverprovider_.quitDriver(browser_.driver);
// Copy mock modules, but do not navigate to previous URL.
browser_ = browser_.forkNewDriverInstance(false, true);
self.setupGlobals_(browser_);
};

return browser_;
};

Expand Down Expand Up @@ -304,14 +314,8 @@ Runner.prototype.run = function() {

if (self.config_.restartBrowserBetweenTests) {
var restartDriver = function() {
// Note: because tests are not paused at this point, any async
// calls here are not guaranteed to complete before the tests resume.
self.driverprovider_.quitDriver(browser_.driver);
// Copy mock modules, but do not navigate to previous URL.
browser_ = browser_.forkNewDriverInstance(false, true);
self.setupGlobals_(browser_);
browser_.restart();
};

self.on('testPass', restartDriver);
self.on('testFail', restartDriver);
}
Expand Down

0 comments on commit 97e6703

Please sign in to comment.