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

Fix: Now correctly allows to override ElementFinder and ElementArrayFinder methods #5328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 17 additions & 19 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ export class ElementArrayFinder extends WebdriverWebElement {
public browser_: ProtractorBrowser, public getWebElements: () => Promise<WebElement[]> = null,
public locator_?: any, public actionResults_: Promise<any> = null) {
super();

// TODO(juliemr): might it be easier to combine this with our docs and just
// wrap each one explicity with its own documentation?
WEB_ELEMENT_FUNCTIONS.forEach((fnName: string) => {
this[fnName] = (...args: any[]) => {
let actionFn = (webElem: any) => {
return webElem[fnName].apply(webElem, args);
};
return this.applyAction_(actionFn);
};
});
}

/**
Expand Down Expand Up @@ -730,6 +719,16 @@ export class ElementArrayFinder extends WebdriverWebElement {
return this.applyAction_(allowAnimationsTestFn);
}
}
// TODO(juliemr): might it be easier to combine this with our docs and just
// wrap each one explicity with its own documentation?
WEB_ELEMENT_FUNCTIONS.forEach((fnName) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if fnName can be only string you could add this type

ElementArrayFinder.prototype[fnName] = function (...args: any[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need here () as you did for ElementFinder ((ElementFinder.prototype[fnName]))?

let actionFn = (webElem: any) => {
return webElem[fnName].apply(webElem, args);
};
return this.applyAction_(actionFn);
};
});

/**
* The ElementFinder simply represents a single element of an
Expand Down Expand Up @@ -827,14 +826,6 @@ export class ElementFinder extends WebdriverWebElement {
this.elementArrayFinder_ = new ElementArrayFinder(
this.browser_, getWebElements, elementArrayFinder.locator(),
elementArrayFinder.actionResults_);

WEB_ELEMENT_FUNCTIONS.forEach((fnName: string) => {
(this)[fnName] = (...args: any[]) => {
return (this.elementArrayFinder_)[fnName]
.apply(this.elementArrayFinder_, args)
.toElementFinder_();
};
});
}

static fromWebElement_(browser: ProtractorBrowser, webElem: WebElement, locator?: Locator):
Expand Down Expand Up @@ -1132,6 +1123,13 @@ export class ElementFinder extends WebdriverWebElement {
return a.getDriver().executeScript('return arguments[0] === arguments[1]', a, b);
}
}
WEB_ELEMENT_FUNCTIONS.forEach((fnName) => {
(ElementFinder.prototype)[fnName] = function (...args: any[]) {
return (this.elementArrayFinder_)[fnName]
.apply(this.elementArrayFinder_, args)
.toElementFinder_();
};
});

/**
* Shortcut for querying the document directly with css.
Expand Down