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

fix(restart): typescript fix for browser.restart #3651

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
4 changes: 3 additions & 1 deletion lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
67 changes: 32 additions & 35 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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) => {
return resolved.reduce((childrenList, resolvedE) => {
return childrenList.concat(resolvedE);
}, []);
});
});
}
};
return new ElementArrayFinder(this.browser_, getWebElements, locator);
Expand Down Expand Up @@ -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<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 +721,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 +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
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
4 changes: 3 additions & 1 deletion lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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_);
};

Expand Down