diff --git a/lib/browser.ts b/lib/browser.ts index 4c9ae714b..54a40c3dd 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -758,7 +758,7 @@ export class ProtractorBrowser extends Webdriver { clientSideScripts.testForAngular, msg('test for angular'), Math.floor(timeout / 1000), this.ng12Hybrid) .then( - (angularTestResult: {ver: string, message: string}) => { + (angularTestResult: {ver: number, message: string}) => { let angularVersion = angularTestResult.ver; if (!angularVersion) { let message = angularTestResult.message; @@ -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. diff --git a/lib/driverProviders/driverProvider.ts b/lib/driverProviders/driverProvider.ts index fc67b5cd7..dd3346b7c 100644 --- a/lib/driverProviders/driverProvider.ts +++ b/lib/driverProviders/driverProvider.ts @@ -4,7 +4,9 @@ * it down, and setting up the driver correctly. */ import * as q from 'q'; + import {Config} from '../config'; + let webdriver = require('selenium-webdriver'); export class DriverProvider { @@ -61,7 +63,7 @@ export class DriverProvider { if (driver.getSession() === undefined) { deferred.resolve(); } else { - driver.getSession().then((session_: string) => { + driver.getSession().then((session_) => { if (session_) { driver.quit().then(function() { deferred.resolve(); diff --git a/lib/element.ts b/lib/element.ts index d9fead9b5..6083eab09 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -178,32 +178,25 @@ 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> - 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> + 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> 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> and merge + // into a single list + return wdpromise.all(childrenPromiseList).then((resolved) => { + return resolved.reduce((childrenList, resolvedE) => { + return childrenList.concat(resolvedE); + }, []); + }); + }); } }; return new ElementArrayFinder(this.browser_, getWebElements, locator); @@ -501,7 +494,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 { + then( + fn?: (value: any) => {} | wdpromise.IThenable<{}>, + errorFn?: (error: any) => any): wdpromise.Promise { if (this.actionResults_) { return this.actionResults_.then(fn, errorFn); } else { @@ -726,7 +721,7 @@ export class ElementArrayFinder extends WebdriverWebElement { export class ElementFinder extends WebdriverWebElement { parentElementArrayFinder: ElementArrayFinder; elementArrayFinder_: ElementArrayFinder; - then: (fn: Function, errorFn: Function) => wdpromise.Promise = null; + then: (fn: Function, errorFn?: Function) => wdpromise.Promise = null; constructor( public browser_: ProtractorBrowser, @@ -751,14 +746,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 diff --git a/lib/expectedConditions.ts b/lib/expectedConditions.ts index a44c6a390..c01d833ef 100644 --- a/lib/expectedConditions.ts +++ b/lib/expectedConditions.ts @@ -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; }); }; diff --git a/lib/runner.ts b/lib/runner.ts index 10da89d8b..a5c73a2a1 100644 --- a/lib/runner.ts +++ b/lib/runner.ts @@ -14,6 +14,7 @@ import * as helper from './util'; declare var global: any; declare var process: any; +declare var Object: any; var webdriver = require('selenium-webdriver'); let logger = new Logger('runner'); @@ -258,7 +259,8 @@ export class Runner extends EventEmitter { // calls here are not guaranteed to complete before the tests resume. this.driverprovider_.quitDriver(browser_.driver); // Copy mock modules, but do not navigate to previous URL. - browser_ = browser_.forkNewDriverInstance(false, true); + let forkBrowser = browser_.forkNewDriverInstance(false, true); + browser_.driver = forkBrowser.driver; this.setupGlobals_(browser_); };