-
Notifications
You must be signed in to change notification settings - Fork 2.3k
browser.restart
should return a promise which resolves when the new browser is ready
#3899
Comments
browser.restart
should return a problem which resolves when the new browser is readybrowser.restart
should return a promise which resolves when the new browser is ready
Blocked on #3902 |
Wrapping it in a `q` promise is blocking angular#3899 Closes angular#3902 Custom frameworks might not make this change but it'll be fine. It'll only be a problem in edge cases and they probably weren't returning the right promise before anyway.
Better solution to the original problem: browser_.restart = () => {
const driverPromise: wdpromise.Promise<WebDriver> = browser_.ready().then(() => {
return this.driverprovider_.quitDriver(browser_.driver);
}).then<WebDriver>(() => {
return browser_.forkNewUnwrappedDriverInstance(false, true);
});
const flow = browser.driver.controlFlow();
const executor = browser.driver.getExecutor();
const session = driverPromise.then(driver => driver.getSession());
const onQuit = extractOnQuit(driverPromise);
browser_.setDriver_(new WebDriver(session, executor, flow, onQuit));
return browser_.ready();
}; Unfortunately, the only function extractOnQuit(driverPromise: wdpromise.Promise<WebDriver>) {
return function() {
const args = arguments;
return driverPromise.then((driver) => {
if ((driver as any).onQuit_) {
return (driver as any).onQuit_.apply(this, args);
} else {
const originalSchedule = driver.schedule;
driver.schedule = () => driver.flow.promise<void>(resolve => resolve());
const result = driver.quit().catch(function() {}); // catch any errors from double quit
driver.schedule = originalSchedule;
}
});
};
} This implementation is actually even worse than it looks, because it makes Using a new |
I think I like the clarity of just splitting based on control flow. If we use // in runner.ts
browser_.restart = () => {
if (wdpromise.USE_PROMISE_MANAGER === false) {
let myPromise = this.driverprovider_.quitDriver(browser._driver).then(() => {
return this.driverprovider_.getNewDriver();
}).then((wd) => {
return browser_.setDriver_(newDriver);
}).then(() => {
return driver.manage().timeouts().setScriptTimeout(this.config_.allScriptsTimeout);
});
return myPromise;
} else {
// we're using the control flow
this.driverprovider_.quitDriver(browser._driver);
browser_.setDriver(this.driverprovider_.getNewDriver());
return driver.manage().timeouts().setScriptTimeout(this.config_.allScriptsTimeout);
}
} This should work with the control flow off - we return a promise which does everything we need. With the control flow on, we've set the driver synchronously, so commands which come next should be scheduled sensibly on the new driver. |
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular#3899 and angular#3896
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular#3899 and angular#3896
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular#3899 and angular#3896
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular#3899 and angular#3896
angular#3992) Wrapping it in a `q` promise is blocking angular#3899 Closes angular#3902 Custom frameworks might not make this change but it'll be fine. It'll only be a problem in edge cases and they probably weren't returning the right promise before anyway.
For the record, |
angular#3992) Wrapping it in a `q` promise is blocking angular#3899 Closes angular#3902 Custom frameworks might not make this change but it'll be fine. It'll only be a problem in edge cases and they probably weren't returning the right promise before anyway.
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular#3899 and angular#3896
…y (#3992) Wrapping it in a `q` promise is blocking angular/protractor#3899 Closes angular/protractor#3902 Custom frameworks might not make this change but it'll be fine. It'll only be a problem in edge cases and they probably weren't returning the right promise before anyway.
Also allows `browser.restart` to work when the control flow is disabled, and fixes it for forked browsers. Closes angular/protractor#3899 and angular/protractor#3896
Proposed implementation:
I know this is messy but:
Should the control flow be on, the fork/overwrite needs to be synchronous to support code like:
Should the control flow be off, we shouldn't do the fork/overwrite until after we've quit, or else we'll briefly have two browser instances floating around. Also, it'd just be weird and unexpected for the global browser instance to change synchronously when you're used to nothing happening until you
await
it.The text was updated successfully, but these errors were encountered: