webdriverio-boneyard / wdio-sync

A WebdriverIO v4 plugin. Helper module to run WebdriverIO commands synchronously.
http://v4.webdriver.io
MIT License
17 stars 31 forks source link

applyPrototype corrupts prototype chain of native objects #37

Closed acthp closed 7 years ago

acthp commented 8 years ago

Return value of saveScreenshot (Buffer) is incorrect due to adding an object to the prototype chain via Object.create. This makes all the native methods on Buffer fail, including the writeFileSync example in the docs. Adding Buffer.isBuffer(result) to the early-return condition fixes this case, though avoiding Object.create might be more robust. :-p

christian-bromann commented 7 years ago

@acthp thanks for filing the issue. I made sure that we don't overload buffer results.

though avoiding Object.create might be more robust

I don't think we can do that. It allows us to inspect command results directly:

console.log(browser.click(".selector"));
// returns { "status": 0, ... }

and chain results:

browser.click(".selector").getTitle();

However I believe this could be limited for element commands only since you usually only work with those results to chain with calls with other commands. I am not sure though yet if this limits other features. However overwriting the prototype of the plain result object shouldn't bring any side effects.