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

Commit

Permalink
chore(types): fix transpile errors related to IThenable
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina committed Oct 20, 2016
1 parent cc45940 commit b111c02
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ export class ProtractorBrowser extends Webdriver {
.then(loadMocks, deferred.reject);

let self = this;
function loadMocks(angularVersion: number) {
if (angularVersion === 1) {
function loadMocks(angularVersion: string) {
if (angularVersion == '1') {
// At this point, Angular will pause for us until
// angular.resumeBootstrap
// is called.
Expand Down
5 changes: 4 additions & 1 deletion lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* it down, and setting up the driver correctly.
*/
import * as q from 'q';
import {Session} from 'selenium-webdriver';

import {Config} from '../config';

let webdriver = require('selenium-webdriver');

export class DriverProvider {
Expand Down Expand Up @@ -61,7 +64,7 @@ export class DriverProvider {
if (driver.getSession() === undefined) {
deferred.resolve();
} else {
driver.getSession().then((session_: string) => {
driver.getSession().then((session_: Session) => {
if (session_) {
driver.quit().then(function() {
deferred.resolve();
Expand Down
70 changes: 35 additions & 35 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,32 +178,28 @@ export class ElementArrayFinder extends WebdriverWebElement {
}
});
} else {
return this.getWebElements().then(
(parentWebElements: webdriver.WebElement[]) => {
// For each parent web element, find their children and construct
// a
// list of Promise<List<child_web_element>>
let childrenPromiseList = parentWebElements.map(
(parentWebElement: webdriver.WebElement) => {
return locator.findElementsOverride ?
locator.findElementsOverride(
ptor.driver, parentWebElement, ptor.rootEl) :
parentWebElement.findElements(locator);
});
return this.getWebElements().then((parentWebElements: WebElement[]) => {
// For each parent web element, find their children and construct
// a list of Promise<List<child_web_element>>
let childrenPromiseList = parentWebElements.map(
(parentWebElement: webdriver.WebElement) => {
return locator.findElementsOverride ?
locator.findElementsOverride(
ptor.driver, parentWebElement, ptor.rootEl) :
parentWebElement.findElements(locator);
});

// Resolve the list of Promise<List<child_web_elements>> and merge
// into
// a single list
return wdpromise.all(childrenPromiseList)
.then((resolved: webdriver.WebElement[]) => {
return resolved.reduce(
(childrenList: webdriver.WebElement[],
resolvedE: webdriver.WebElement) => {
return childrenList.concat(resolvedE);
},
[]);
});
});
// Resolve the list of Promise<List<child_web_elements>> and merge
// into a single list
return wdpromise.all(childrenPromiseList).then((resolved: any) => {
return resolved.reduce(
(childrenList: WebElement[],
resolvedE: webdriver.WebElement) => {
return childrenList.concat(resolvedE);
},
[]);
});
});
}
};
return new ElementArrayFinder(this.browser_, getWebElements, locator);
Expand Down Expand Up @@ -501,7 +497,9 @@ 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): wdpromise.Promise<any[]> {
then(
fn?: (value: any) => {} | wdpromise.IThenable<{}>,
errorFn?: (error: any) => any): wdpromise.Promise<any[]> {
if (this.actionResults_) {
return this.actionResults_.then(fn, errorFn);
} else {
Expand Down Expand Up @@ -726,7 +724,7 @@ export class ElementArrayFinder extends WebdriverWebElement {
export class ElementFinder extends WebdriverWebElement {
parentElementArrayFinder: ElementArrayFinder;
elementArrayFinder_: ElementArrayFinder;
then: (fn: Function, errorFn: Function) => wdpromise.Promise<any> = null;
then: (fn: Function, errorFn?: Function) => wdpromise.Promise<any> = null;

constructor(
public browser_: ProtractorBrowser,
Expand All @@ -751,14 +749,16 @@ export class ElementFinder extends WebdriverWebElement {
* of
* evaluating fn.
*/
this.then = (fn: Function, errorFn: Function) => {
return this.elementArrayFinder_.then((actionResults: any) => {
if (!fn) {
return actionResults[0];
}
return fn(actionResults[0]);
}, errorFn);
};
this.then =
(fn: (value: any) => {} | wdpromise.IThenable<{}>,
errorFn?: (error: any) => any) => {
return this.elementArrayFinder_.then((actionResults: any) => {
if (!fn) {
return actionResults[0];
}
return fn(actionResults[0]);
}, errorFn);
};
}

// This filter verifies that there is only 1 element returned by the
Expand Down
3 changes: 2 additions & 1 deletion lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export class ProtractorExpectedConditions {
Function {
var hasText = () => {
return elementFinder.getText().then((actualText: string): boolean => {
// MSEdge does not properly remove newlines, which causes false negatives
// MSEdge does not properly remove newlines, which causes false
// negatives
return actualText.replace(/\r?\n|\r/g, '').indexOf(text) > -1;
});
};
Expand Down

0 comments on commit b111c02

Please sign in to comment.