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

feat(browser.ready): make browser.ready wait for all async setup work #4015

Merged
merged 1 commit into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the wrapping in execute here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.driver.getSession() is not necessarily a promise which is on the control flow, so this is needed to ensure that the other stuff we stick onto browser.ready is on the control flow

.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