Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

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 (#4015)

Closes #3900
  • Loading branch information
sjelin authored Jan 26, 2017
1 parent ed2534a commit f11fece
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 @@ -348,7 +348,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 @@ -370,17 +369,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 f11fece

Please sign in to comment.