Skip to content

Commit

Permalink
feat(browser.ready): make browser.ready wait for all async setup wo…
Browse files Browse the repository at this point in the history
…rk (angular#4015)

Closes angular#3900
  • Loading branch information
sjelin committed Jan 27, 2017
1 parent b77cb92 commit 7cb9739
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
28 changes: 16 additions & 12 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
this.ignoreSynchronization = false;
this.getPageTimeout = DEFAULT_GET_PAGE_TIMEOUT;
this.params = {};
this.ready = null;
this.plugins_ = new Plugins({});
this.resetUrl = DEFAULT_RESET_URL;
this.debugHelper = new DebugHelper(this);
Expand All @@ -451,17 +450,22 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
ng12Hybrid_ = ng12Hybrid;
}
});
this.driver.getCapabilities().then((caps: Capabilities) => {
// Internet Explorer does not accept data URLs, which are the default
// reset URL for Protractor.
// Safari accepts data urls, but SafariDriver fails after one is used.
// PhantomJS produces a "Detected a page unload event" if we use data urls
let browserName = caps.get('browserName');
if (browserName === 'internet explorer' || browserName === 'safari' ||
browserName === 'phantomjs' || browserName === 'MicrosoftEdge') {
this.resetUrl = 'about:blank';
}
});
this.ready = this.driver.controlFlow()
.execute(() => {
return this.driver.getSession();
})
.then((session: Session) => {
// Internet Explorer does not accept data URLs, which are the default
// reset URL for Protractor.
// Safari accepts data urls, but SafariDriver fails after one is used.
// PhantomJS produces a "Detected a page unload event" if we use data urls
let browserName = session.getCapabilities().get('browserName');
if (browserName === 'internet explorer' || browserName === 'safari' ||
browserName === 'phantomjs' || browserName === 'MicrosoftEdge') {
this.resetUrl = 'about:blank';
}
return this;
});

this.trackOutstandingTimeouts_ = !opt_untrackOutstandingTimeouts;
this.mockModules_ = [];
Expand Down
21 changes: 17 additions & 4 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ export class Runner extends EventEmitter {
}

browser_.ready =
driver.manage().timeouts().setScriptTimeout(config.allScriptsTimeout).then(() => browser_);
browser_.ready
.then(() => {
return driver.manage().timeouts().setScriptTimeout(config.allScriptsTimeout);
})
.then(() => {
return browser_;
});

browser_.getProcessedConfig = () => {
return wdpromise.fulfilled(config);
Expand All @@ -261,9 +267,16 @@ export class Runner extends EventEmitter {
newBrowser.mockModules_ = browser_.mockModules_;
}
if (opt_useSameUrl) {
browser_.driver.getCurrentUrl().then((url: string) => {
newBrowser.get(url);
});
newBrowser.ready = newBrowser.ready
.then(() => {
return browser_.driver.getCurrentUrl();
})
.then((url: string) => {
return newBrowser.get(url);
})
.then(() => {
return newBrowser;
});
}
return newBrowser;
};
Expand Down

0 comments on commit 7cb9739

Please sign in to comment.