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

Unhandled promise rejection in index.js:348:63 (Stacktrace inside) #72

Closed dheerajbhaskar closed 7 years ago

dheerajbhaskar commented 7 years ago

Context

I use selenium automation scripts written in webdriverio where it runs a few commands and it stops waiting for all elements (in a CSS selector) to disappear. This used to randomly kill my node process with UnhandledPromiseRejection and no stacktrace, I couldn't make headway in fixing this error at all and used to encounter it every few minutes and I used to restart my wdio tests. Now I've gotten the stacktrace, I'm posting it while I myself investigate this further.

This code got me the stacktrace

process.on('unhandledRejection', function(err, promise) {
    console.error('Unhandled rejection (promise: ', promise, ', reason: ', err, ').');
});

Stactrace

Unhandled rejection (promise:  Promise {
  <rejected> TypeError: Cannot read property 'ELEMENT' of undefined
    at is$$Result (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\wdio-
sync\build\index.js:348:63)
    at Object.applyPrototype (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_mo
dules\wdio-sync\build\index.js:363:199)
    at Object.<anonymous> (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modul
es\wdio-sync\build\index.js:322:63)
    at Object.exec (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\webd
riverio\build\lib\helpers\safeExecute.js:28:24)
    at Object.resolve (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\w
ebdriverio\build\lib\webdriverio.js:193:29)
    at C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\webdriverio\build
\lib\webdriverio.js:503:32
    at _fulfilled (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\q\q.j
s:834:54)
    at self.promiseDispatch.done (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\nod
e_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-ne
db\node_modules\q\q.js:796:13)
    at C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\q\q.js:604:44 } ,
 reason:  TypeError: Cannot read property 'ELEMEN
T' of undefined
    at is$$Result (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\wdio-
sync\build\index.js:348:63)
    at Object.applyPrototype (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_mo
dules\wdio-sync\build\index.js:363:199)
    at Object.<anonymous> (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modul
es\wdio-sync\build\index.js:322:63)
    at Object.exec (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\webd
riverio\build\lib\helpers\safeExecute.js:28:24)
    at Object.resolve (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\w
ebdriverio\build\lib\webdriverio.js:193:29)
    at C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\webdriverio\build
\lib\webdriverio.js:503:32
    at _fulfilled (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\q\q.j
s:834:54)
    at self.promiseDispatch.done (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\nod
e_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (C:\my-home\AutomationProjects\WebdriverioProjects\chimp-ne
db\node_modules\q\q.js:796:13)
    at C:\my-home\AutomationProjects\WebdriverioProjects\chimp-nedb\node_modules\q\q.js:604:44 ).
dheerajbhaskar commented 7 years ago

The is$$Result function for me appears on line 200, while the stacktrace says line 348. I'm now wondering if I'm looking at the right package in node_modules (I'm looking at wdio-sync), can there be multiple copies of a package in node_modules, I remember reading somewhere that npm is notorious for having multiple instances of same package, I shall continue searching

screenshot 9 cropped

dheerajbhaskar commented 7 years ago

Oh!, wdio must be referencing the file under the build directory, the line number matches: screenshot 85 _cropped

dheerajbhaskar commented 7 years ago

updating the line number 348 to the following seems to work:

return Array.isArray(result) && result.length && result[0] && result[0].ELEMENT !== undefined;

I've not seen any crashes, but that doesn't mean its working, perhaps I need to put in a if block there to console.log whenever result[0] is undefined but result.length is truthy. Seems odd why that would happen, but this is just a temporary fix, I've not dug deeper yet.

dheerajbhaskar commented 7 years ago

I see that this is already fixed. See screenshot:

screenshot 86 _cropped

Is this not in npm yet? Let me check

christian-bromann commented 7 years ago

@dheerajbhaskar no but I can release it

dheerajbhaskar commented 7 years ago

Please do release it, Christian

christian-bromann commented 7 years ago

Already done