angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Some references to files are missing in stack trace with async/await #4600

Open tsharan opened 6 years ago

tsharan commented 6 years ago

Stacktrace is not having the reference to actual file name from where the error is triggered for the protractor.

Protractor version: 5.1.2

configuration:

   exports.config = {
    framework: 'jasmine2',
    jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 300000,
    print: function () {
    }
  }
 onPrepare()
  {
    jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true,}}));
  }

Sample spec:

 it('Protractor stack trace issue', async () =>
     { 
       const helper = new SearchHelper(); 
       await helper.doSearch('test'); 
    });

search-helper.ts:

    async doSearch(text) { 
      await browser.get('http://google.com'); 
      await browser.wait(EC.visibilityOf(element(by.name('q1'))), 10000, 'No Element found'); 
      await element(by.name('q1')).click(); //invalid locator 
    }

1. Stack Trace with browser.wait

✗ Protractor stack trace issue 
    -Failed: No Element found Wait timed out after 10007ms
    Wait timed out after 10007ms 
    at WebDriverError (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:27:5) 
    at TimeoutError (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:238:5) 
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2107:17 
    at process._tickCallback (internal/process/next_tick.js:109:7) 

    From asynchronous test: Error at Suite.<anonymous> (/Users/e2e/sample-spec.ts:27:3) 
    at Object.<anonymous> (/Users/e2e/sample-spec.ts:15:1) 
    at Module._compile (module.js:570:32) at Module.m._compile (/Users/node_modules/ts-node/src/index.ts:392:23) 
    at Module._extensions..js (module.js:579:10) 
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/node_modules/ts-node/src/index.ts:395:12)

2. If we comment browser.wait statement then the stacktrace is

✗ Protractor stack trace issue 
     Failed: No element found using locator: By(css selector, *[name="q1"]) 
     at WebDriverError (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:27:5) 
     at NoSuchElementError (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:168:5) 
     at elementArrayFinder.getWebElements.then (/usr/local/lib/node_modules/protractor/lib/element.ts:851:17) 
     at process._tickCallback (internal/process/next_tick.js:109:7)Error 
     at ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/lib/element.ts:482:23) 
     at ElementArrayFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.ts:96:21) 
     at ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.ts:873:14) 
     at SearchHelper.<anonymous> (/Users/e2e/search-helper.ts:14:34) **at step (/Users/e2e/search-helper.ts:32:23) 
     at Object.next (/Users/e2e/search-heper.ts:13:53) 
     at fulfilled (/Users/e2e/search-helper.ts:4:58)** 
     at process._tickCallback (internal/process/next_tick.js:109:7) 

     From asynchronous test: Error at Suite.<anonymous> (/Users/e2e/sample-spec.ts:27:3) 
     at Object.<anonymous> (/Users/e2e/sample-spec.ts:15:1) at Module._compile (module.js:570:32) 
     at Module.m._compile (/Users/node_modules/ts-node/src/index.ts:392:23) 
     at Module._extensions..js (module.js:579:10) 
     at Object.require.extensions.(anonymous function) [as .ts] (/Users/node_modules/ts-node/src/index.ts:395:12)

Observe the 2nd stack trace, it has references to search-helper file but it's not there in the first stack trace. It's very important to have this reference in stack trace for debugging.

tsharan commented 6 years ago

Any suggestions?

amilbeck commented 6 years ago

How is this issue not getting more traction? @tsharan and I can't be the only people with this problem. In my case, I'm not getting anything useful at all that lets me know what the problem is. This is not the first time I've noticed this in the last couple weeks. I'm in the process of migrating all of our tests to use the async/await pattern and I've run into this problem several times along the way. I've even tried setting the logLevel to 'DEBUG' and I'm still not getting anything more than the basic jasmine default timeout error. What am I missing? I feel like there is something I must not know about using async/await or more people would be complaining about this problem.

Here is my super useful stacktrace:

× should do something
        - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
            at ontimeout (timers.js:386:11)
            at tryOnTimeout (timers.js:250:5)

**************************************************
*                    Failures                    *
**************************************************

1) Smoke Tests - should do something
  - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

Executed 14 of 14 specs (1 FAILED) in 1 min 12 secs.

Thankfully, I was actively working on this test so I knew exactly what was wrong but if this test had failed as part of a deployment verification process, aside from the spec that actually failed, I wouldn't have a clue where to start looking .

vadimromanyak commented 6 years ago

Experience the same issue described by @tsharan. Browser.wait shortens the stack trace, so it is not useful any more for debug purpose.

amilbeck commented 6 years ago

For what it's worth, I think the way to get some stacktraces that are actually useful in this situation is to wrap everything in a try/catch block. I usually skip this part but it's technically the right way to use async/await. Once you catch the error you can just log it to the console to see something useful.

vadimromanyak commented 6 years ago

Try/catch definitely should be used. Though, it still doesn't solve the problem.

Referring to tsharan original samples. Stack trace shows reference to method doSearch from search-helper.ts, but doesn't show reference to where it was called in Sample spec.

rkrisztian commented 5 years ago

I think the solution is here: https://github.com/nodejs/node/issues/11865

Edit: Checked Node.js 12.4.0, but it did not solve the problem out of the box.

niyarlatotep commented 5 years ago

Try Error.stackTraceLimit = Infinity; in your code. Works with Node.js 12.x.x

endqwerty commented 3 years ago

I've tried the Error.stackTraceLimit = Infinity; solution but that didn't work for me, does anyone else still have this issue? or did anyone solve this using a different solution?

I'm using node 12.16.1