diff --git a/lib/browser.ts b/lib/browser.ts index ce25aefd0..ba7a78ed5 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -34,16 +34,18 @@ for (let foo in webdriver) { export class Webdriver { actions: () => webdriver.ActionSequence = webdriver.WebDriver.actions; wait: - (condition: webdriver.promise.Promise|webdriver.util.Condition|Function, + (condition: webdriver.promise.Promise | webdriver.util.Condition | + Function, opt_timeout?: number, opt_message?: - string) => webdriver.promise.Promise = webdriver.WebDriver.wait; - sleep: (ms: number) => webdriver.promise.Promise = webdriver.WebDriver.sleep; + string) => webdriver.promise.Promise = webdriver.WebDriver.wait; + sleep: (ms: number) => webdriver.promise.Promise = + webdriver.WebDriver.sleep; getCurrentUrl: - () => webdriver.promise.Promise = webdriver.WebDriver.getCurrentUrl; - getTitle: () => webdriver.promise.Promise = webdriver.WebDriver.getTitle; + () => webdriver.promise.Promise = webdriver.WebDriver.getCurrentUrl; + getTitle: () => webdriver.promise.Promise = webdriver.WebDriver.getTitle; takeScreenshot: - () => webdriver.promise.Promise = webdriver.WebDriver.takeScreenshot; + () => webdriver.promise.Promise = webdriver.WebDriver.takeScreenshot; } /** @@ -188,7 +190,7 @@ export class Browser extends Webdriver { * * @type {q.Promise} Done when the new browser is ready for use */ - ready: webdriver.promise.Promise; + ready: webdriver.promise.Promise; /* * Set by the runner. @@ -247,6 +249,7 @@ export class Browser extends Webdriver { // include functions which are overridden by protractor below. let methodsToSync = ['getCurrentUrl', 'getPageSource', 'getTitle']; + // Mix all other driver functionality into Protractor. Object.getOwnPropertyNames(webdriver.WebDriver.prototype) .forEach((method: string) => { @@ -300,7 +303,7 @@ export class Browser extends Webdriver { * * @returns {webdriver.promise.Promise} A promise which resolves to the capabilities object. */ - getProcessedConfig: () => webdriver.promise.Promise; + getProcessedConfig: () => webdriver.promise.Promise; /** * Fork another instance of protractor for use in interactive tests. @@ -346,7 +349,7 @@ export class Browser extends Webdriver { */ private executeScript_( script: string|Function, description: string, - ...scriptArgs: any[]): webdriver.promise.Promise { + ...scriptArgs: any[]): webdriver.promise.Promise { if (typeof script === 'function') { script = 'return (' + script + ').apply(null, arguments);'; } @@ -372,7 +375,7 @@ export class Browser extends Webdriver { */ private executeAsyncScript_( script: string|Function, description: string, - ...scriptArgs: any[]): webdriver.promise.Promise { + ...scriptArgs: any[]): webdriver.promise.Promise { if (typeof script === 'function') { script = 'return (' + script + ').apply(null, arguments);'; } @@ -394,7 +397,7 @@ export class Browser extends Webdriver { * @returns {!webdriver.promise.Promise} A promise that will resolve to the * scripts return value. */ - waitForAngular(opt_description?: string): webdriver.promise.Promise { + waitForAngular(opt_description?: string): webdriver.promise.Promise { let description = opt_description ? ' - ' + opt_description : ''; if (this.ignoreSynchronization) { return this.driver.controlFlow().execute(() => { @@ -402,7 +405,7 @@ export class Browser extends Webdriver { }, 'Ignore Synchronization Protractor.waitForAngular()'); } - let runWaitForAngularScript: () => webdriver.promise.Promise = () => { + let runWaitForAngularScript: () => webdriver.promise.Promise = () => { if (this.plugins_.skipAngularStability()) { return webdriver.promise.fulfilled(); } else if (this.rootEl) { @@ -462,7 +465,7 @@ export class Browser extends Webdriver { errMsg += '\nWhile waiting for element with locator' + description; } - let pendingTimeoutsPromise: webdriver.promise.Promise; + let pendingTimeoutsPromise: webdriver.promise.Promise; if (this.trackOutstandingTimeouts_) { pendingTimeoutsPromise = this.executeScript_( 'return window.NG_PENDING_TIMEOUTS', @@ -528,7 +531,7 @@ export class Browser extends Webdriver { * @returns {!webdriver.promise.Promise} A promise that will be resolved to an * array of the located {@link webdriver.WebElement}s. */ - findElements(locator: Locator): webdriver.promise.Promise { + findElements(locator: Locator): webdriver.promise.Promise { return this.element.all(locator).getWebElements(); } @@ -539,7 +542,7 @@ export class Browser extends Webdriver { * the element is present on the page. */ isElementPresent(locatorOrElement: webdriver.Locator| - webdriver.WebElement): webdriver.promise.Promise { + webdriver.WebElement): webdriver.promise.Promise { let element = (locatorOrElement.isPresent) ? locatorOrElement : this.element(locatorOrElement); return element.isPresent(); @@ -857,7 +860,7 @@ export class Browser extends Webdriver { * @returns {!webdriver.promise.Promise} A promise that will resolve once * page has been changed. */ - setLocation(url: string): webdriver.promise.Promise { + setLocation(url: string): webdriver.promise.Promise { this.waitForAngular(); return this .executeScript_( @@ -880,7 +883,7 @@ export class Browser extends Webdriver { * .toBe('http://angular.github.io/protractor/#/api'); * @returns {string} The current absolute url from AngularJS. */ - getLocationAbsUrl(): webdriver.promise.Promise { + getLocationAbsUrl(): webdriver.promise.Promise { this.waitForAngular(); return this.executeScript_( clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', @@ -924,7 +927,8 @@ export class Browser extends Webdriver { * is done. The promise will resolve to a boolean which represents whether * this is the first time that the debugger is called. */ - private validatePortAvailability_(port: number): webdriver.promise.Promise { + private validatePortAvailability_(port: number): + webdriver.promise.Promise { if (this.debuggerValidated_) { return webdriver.promise.fulfilled(false); } diff --git a/lib/element.ts b/lib/element.ts index 896be987c..cc9c4d63f 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -17,27 +17,27 @@ let WEB_ELEMENT_FUNCTIONS = [ // Explicitly define webdriver.WebElement. export class WebdriverWebElement { getDriver: () => webdriver.WebDriver; - getId: () => webdriver.promise.Promise; - getRawId: () => webdriver.promise.Promise; - serialize: () => webdriver.promise.Promise; - findElement: (subLocator: Locator) => webdriver.promise.Promise; - click: () => webdriver.promise.Promise; - sendKeys: (...args: (string|webdriver.promise.Promise)[]) => - webdriver.promise.Promise; - getTagName: () => webdriver.promise.Promise; - getCssValue: (cssStyleProperty: string) => webdriver.promise.Promise; - getAttribute: (attributeName: string) => webdriver.promise.Promise; - getText: () => webdriver.promise.Promise; - getSize: () => webdriver.promise.Promise; - getLocation: () => webdriver.promise.Promise; - isEnabled: () => webdriver.promise.Promise; - isSelected: () => webdriver.promise.Promise; - submit: () => webdriver.promise.Promise; - clear: () => webdriver.promise.Promise; - isDisplayed: () => webdriver.promise.Promise; - takeScreenshot: (opt_scroll?: boolean) => webdriver.promise.Promise; - getOuterHtml: () => webdriver.promise.Promise; - getInnerHtml: () => webdriver.promise.Promise; + getId: () => webdriver.promise.Promise; + getRawId: () => webdriver.promise.Promise; + serialize: () => webdriver.promise.Promise; + findElement: (subLocator: Locator) => webdriver.promise.Promise; + click: () => webdriver.promise.Promise; + sendKeys: (...args: (string|webdriver.promise.Promise)[]) => + webdriver.promise.Promise; + getTagName: () => webdriver.promise.Promise; + getCssValue: (cssStyleProperty: string) => webdriver.promise.Promise; + getAttribute: (attributeName: string) => webdriver.promise.Promise; + getText: () => webdriver.promise.Promise; + getSize: () => webdriver.promise.Promise<{width: number, height: number}>; + getLocation: () => webdriver.promise.Promise<{x: number, y: number}>; + isEnabled: () => webdriver.promise.Promise; + isSelected: () => webdriver.promise.Promise; + submit: () => webdriver.promise.Promise; + clear: () => webdriver.promise.Promise; + isDisplayed: () => webdriver.promise.Promise; + takeScreenshot: (opt_scroll?: boolean) => webdriver.promise.Promise; + getOuterHtml: () => webdriver.promise.Promise; + getInnerHtml: () => webdriver.promise.Promise; } /** @@ -99,7 +99,7 @@ export class ElementArrayFinder extends WebdriverWebElement { constructor( private browser_: Browser, getWebElements?: Function, private locator_?: any, - public actionResults_: webdriver.promise.Promise = null) { + public actionResults_: webdriver.promise.Promise = null) { super(); this.getWebElements = getWebElements || null; @@ -379,7 +379,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * @returns {!webdriver.promise.Promise} A promise which resolves to the * number of elements matching the locator. */ - count(): webdriver.promise.Promise { + count(): webdriver.promise.Promise { return this.getWebElements().then( (arr: any) => { return arr.length; }, (err: any) => { @@ -439,7 +439,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * @returns {Array.} Return a promise, which resolves to a list * of ElementFinders specified by the locator. */ - asElementFinders_(): webdriver.promise.Promise { + asElementFinders_(): webdriver.promise.Promise { return this.getWebElements().then((arr: webdriver.WebElement[]) => { return arr.map((webElem: webdriver.WebElement) => { return ElementFinder.fromWebElement_( @@ -472,7 +472,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * @returns {!webdriver.promise.Promise} A promise which will resolve to * an array of ElementFinders represented by the ElementArrayFinder. */ - then(fn: Function, errorFn: Function): webdriver.promise.Promise { + then(fn: Function, errorFn: Function): webdriver.promise.Promise { if (this.actionResults_) { return this.actionResults_.then(fn, errorFn); } else { @@ -506,7 +506,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * function has been called on all the ElementFinders. The promise will * resolve to null. */ - each(fn: Function): webdriver.promise.Promise { + each(fn: Function): webdriver.promise.Promise { return this.map(fn).then((): any => { return null; }); } @@ -542,7 +542,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * @returns {!webdriver.promise.Promise} A promise that resolves to an array * of values returned by the map function. */ - map(mapFn: Function): webdriver.promise.Promise { + map(mapFn: Function): webdriver.promise.Promise { return this.asElementFinders_().then((arr: ElementFinder[]) => { let list = arr.map((elementFinder: ElementFinder, index: number) => { let mapResult = mapFn(elementFinder, index); @@ -584,7 +584,8 @@ export class ElementArrayFinder extends WebdriverWebElement { * @returns {!webdriver.promise.Promise} A promise that resolves to the final * value of the accumulator. */ - reduce(reduceFn: Function, initialValue: any): webdriver.promise.Promise { + reduce(reduceFn: Function, initialValue: any): webdriver.promise.Promise + { let valuePromise = webdriver.promise.fulfilled(initialValue); return this.asElementFinders_().then((arr: ElementFinder[]) => { return arr.reduce( @@ -691,7 +692,8 @@ export class ElementArrayFinder extends WebdriverWebElement { export class ElementFinder extends WebdriverWebElement { parentElementArrayFinder: ElementArrayFinder; elementArrayFinder_: ElementArrayFinder; - then: (fn: Function, errorFn: Function) => webdriver.promise.Promise = null; + then: (fn: Function, errorFn: Function) => webdriver.promise.Promise = + null; constructor( private browser_: Browser, elementArrayFinder: ElementArrayFinder) { @@ -1026,7 +1028,7 @@ export class ElementFinder extends WebdriverWebElement { * @returns {!webdriver.promise.Promise.} A promise that will be * resolved to whether the two WebElements are equal. */ - equals(element: any): webdriver.promise.Promise { + equals(element: any): webdriver.promise.Promise { return webdriver.WebElement.equals( this.getWebElement(), element.getWebElement ? element.getWebElement() : element); diff --git a/lib/globals.d.ts b/lib/globals.d.ts index eb8f25295..ca59d0865 100644 --- a/lib/globals.d.ts +++ b/lib/globals.d.ts @@ -63,7 +63,7 @@ declare namespace webdriver { } namespace promise { - interface Promise { + interface Promise { controlFlow: Function; then: Function; }