Skip to content

Commit

Permalink
feat(browser.ready): make browser.ready wait for all async setup work
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin committed Jan 26, 2017
1 parent f4cf277 commit c2dd15c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
27 changes: 15 additions & 12 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,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 @@ -365,17 +364,21 @@ 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';
}
});

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

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

browser_.getProcessedConfig = () => {
return wdpromise.fulfilled(config);
Expand All @@ -258,9 +260,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 c2dd15c

Please sign in to comment.