protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Option to disable uncaughtException listener

Open calendir opened this issue 10 years ago • 19 comments

Please add an option to disable the uncaughtException listener from lib/launcher.ts:182 since it interferes with Cucumber as described in #3491.

Quick recap: Protractor's uncaughtException listener registers first so it's fired before Cucumber's listener for the same event, which would normally handle whatever error occurred inside a step definition and gracefully fail the step. Which in turn leads to Protractor exiting the suite at the first exception (which could be, for example, a failed assertion).

calendir avatar Sep 14 '16 13:09 calendir

It still seems like this is an issue with the framework relying on this and not Protractor itself (since uncaughtException is the last line of defense).

I'm not opposed to adding something like this in but it seems better dealt with at the framework level if possible.

NickTomlin avatar Sep 14 '16 19:09 NickTomlin

I understand your reluctance, but I don't see a way of handling this in protractor-cucumber-framework as all it does is listen to events broadcast by Cucumber and is only made aware of the failure if Cucumber has handled it.

calendir avatar Sep 15 '16 07:09 calendir

+1 It is blocking cucumber.js users. @calendir Would you submit a PR? At least we can we use your branch so we can upgrade.

jlin412 avatar Sep 22 '16 13:09 jlin412

This seems to be an issue! I am aware that uncaught exception event is triggered before the cucumber listeners which is why the steps are failing abruptly incase of errors.

Note : It works fine with Protractor 3.3.0 and uncaught exception was added from 4.0, so I won't say it's a blocker as of now, you could downgrade and check if it works for you.

Meanwhile, There should be an alternative for this to support with newer versions of protractor! @NickTomlin @cnishina any suggestions?

igniteram avatar Sep 22 '16 13:09 igniteram

+1 It is blocking cucumber.js users.

aluzardo avatar Sep 22 '16 14:09 aluzardo

Whoops, I missed that @NickTomlin was taking this in #3491.

According to cucumber/cucumber-js#643, this needs a fix to protractor-cucumber-framework. Thanks for taking care of this, Nick!

Follow up on this issue should be directed to mattfritz/protractor-cucumber-framework#56

heathkit avatar Sep 28 '16 15:09 heathkit

I take that back! It is a problem on our end.... kind of. The mocha and jasmine frameworks both have wrappers that handle exceptions - jasminewd for jasmine and the Mocha wrappers in selenium-webdriver. There's no such wrapper for cucumber, so we've actually never handled webdriver errors, it's just never been an issue since we ignored uncaught exceptions in the past.

It's actually a little surprising cucumber works at all without a webdriver wrapping, but I guess the pattern of putting all your expectations in a "Then" block means all the WebDriver ControlFlow promises will be resolved by the time you check for things.

In any case, this will be fixed in the next point release. Sorry for the breakage.

heathkit avatar Sep 29 '16 08:09 heathkit

If someone need it. I found a temporally workaround to avoid this problem temporally. The workaround is using multiCapabilitiesand more than one browser inside the config.js.

For example:

multiCapabilities: [
        {
            browserName: 'firefox'
        },
        {
            browserName: 'chrome'
        }
    ]

aluzardo avatar Sep 29 '16 09:09 aluzardo

@mgiambalvo thanks for following up on this!

I was working on something similar for the cucumber framework issue (I just updated it with a description of the problem). I was also very surprised that this had been "working" for so long. I think your idea of fixing this in the time being is a much better quick solve. Thanks for taking that on!

NickTomlin avatar Sep 29 '16 17:09 NickTomlin

There is always some integration issue of exception or error handling between cucumber and protractor on and off. Perhaps, this is the root cause and will be resolved once for all!!!

jlin412 avatar Sep 29 '16 17:09 jlin412

Well, unfortunately, this just goes back to the old behavior of ignoring uncaught exceptions from WebDriver. Though we do log a warning message when they happen now (progress!). I'm honestly a little surprised that cucumber works at all without some kind of webdriver wrapper similar to the ones I linked above for jasmine and mocha. I'd like to follow up on this later and find a better long term solution for cucumber.

heathkit avatar Sep 29 '16 23:09 heathkit

Hi There,

When do we anticipate to have a fix for this? Many thanks in advance.

I can roll back to an old version but i'd like to use the latest edition of protractor.

bhreinb avatar Oct 03 '16 15:10 bhreinb

The fix should be included in the next patch release, probably sometime next week.

heathkit avatar Oct 06 '16 02:10 heathkit

Hi Guys, Do we have any info about that release which will include this fix?

szikszail avatar Oct 25 '16 07:10 szikszail

+1

AlexandrosD avatar Oct 27 '16 20:10 AlexandrosD

So I was seeing this same issue. (using protractor, cucumber-protractor-framework, cucumber, webdriverjs) and hoping that when we got the new release (which I presume would be 4.0.10 as it just came out a few days ago.

I updated protractor to the latest, but I find that for my tests, that I still get the failures and an exit with code 199 any time an action in a step fails (when that step's promise is not being returned)

eg I have a step that has two parts, both webdriver calls. the first part clicks an element, the second waits for a spinner modal to go away.. so the code is roughly

$(css-selector).click();
return browser.wait(EC.not(EC.presenceOf($(css-for-spinner))));

if the click fails to find the element, that's the end of the test run, when what you would hope for is just for that scenario to fail and move on to the next one. So it's seeming to me like this is not fixed.

Chuckv avatar Nov 03 '16 23:11 Chuckv

In 4.0.10, there's a new configuration option ignoreUncaughtExceptions. We don't want to turn this on by default, since it could mask difficult to debug WebDriver errors in Jasmine-based testing. Cucumber users will need to turn this option on, though.

heathkit avatar Nov 04 '16 00:11 heathkit

Ah, that makes sense. Found it in the lib/config.ts although I think the comments there could be expanded a bit to impress the importance of this at least for people using cucumber-protractor framework.

(update) having set ignoreUncaughtExceptions: true in the config file, I am now able to run a test suite that was previously failing due to an uncaught exception all the way through without the test run crashing. The scenarios with the exception(s) fail as would be expected, and we get test results for the run instead of nothing but the console feedback.

Chuckv avatar Nov 04 '16 15:11 Chuckv

I somehow stumbled accross this and the fix has saved me so much time. Thanks to everyone involved resolving this.

kieranbop avatar Jan 10 '17 11:01 kieranbop