protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Fix: Now correctly allows to override ElementFinder and ElementArrayFinder methods

Open Xotabu4 opened this issue 6 years ago • 1 comments

Fix: Now correctly allows to override ElementFinder and ElementArrayFinder methods

Monkey-patching was done in ElementFinder constructor against 'this'. It means this monkey-patching is applied AFTER all methods in inherited objects declared - it will just replace them. Here is list of WebElement methods, that is monkey-patched into ElementFinder: let WEB_ELEMENT_FUNCTIONS = [ 'click', 'sendKeys', 'getTagName', 'getCssValue', 'getAttribute', 'getText', 'getRect', 'isEnabled', 'isSelected', 'submit', 'clear', 'isDisplayed', 'getId', 'takeScreenshot' ];

class Component extends ElementFinder {
  constructor(elementFinder: ElementFinder) {
    super(elementFinder.browser_, elementFinder.elementArrayFinder_);
  }

 async click() {
     console.log('OWN click!')
     await super.click()
 }
}

new Component($('button')).click()

Before this PR code above would not be working - since monkey-patching is overrides methods declared in child classes:

https://github.com/Xotabu4/protractor-element-extend/issues/20

Xotabu4 avatar Oct 07 '19 19:10 Xotabu4

@cnishina could you take a look at it useful PR? :)

CrispusDH avatar Oct 08 '19 06:10 CrispusDH