Protractor v4 exits with code 199 when EC or Chai throw an error
Hi, We're using Protractor with Cucumber via the protractor-cucumber-framework and after upgrading from v3.3.0 we've run to a bit of a problem.
With Protractor 4 handling of errors thrown by Expected Conditions and Chai assertions (and possibly anything else) seems to have changed and now if the error is not thrown inside the promise that is returned from the step definition we get a beautiful stack trace and Protractor exits with code 199.
Any ideas?
[12:53:03] E/launcher - Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible.
Wait timed out after 10027ms
[12:53:03] E/launcher - Error: Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible.
Wait timed out after 10027ms
at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2364:22
at ManagedPromise.invokeCallback_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27
at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible.
at ControlFlow.wait (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2352:17)
at WebDriver.wait (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:712:29)
at ProtractorBrowser.to.(anonymous function) [as wait] (protractor-poc/node_modules/protractor/built/browser.js:61:29)
at [object Object].waitForElement (protractor-poc/steps/support/waitForElement.js:40:20)
at [object Object].<anonymous> (protractor-poc/steps/performanceSteps.js:128:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
[12:53:03] E/launcher - Process exited with error code 199
- Node Version:
5.10.1 - Protractor Version:
4.0.3
+1
On Tue, Aug 23, 2016 at 7:08 AM, Oskar B [email protected] wrote:
Hi, We're using Protractor with Cucumber via the protractor-cucumber-framework and after upgrading from v3.3.0 we've run to a bit of a problem.
With Protractor 4 handling of errors thrown by Expected Conditions and Chai assertions (and possibly anything else) seems to have changed and now if the error is not thrown inside the promise that is returned from the step definition we get a beautiful stack trace and Protractor exits with code 199.
Any ideas?
[12:53:03] E/launcher - Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible. Wait timed out after 10027ms [12:53:03] E/launcher - Error: Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible. Wait timed out after 10027ms at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2364:22 at ManagedPromise.invokeCallback_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14) at TaskQueue.execute_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14) at TaskQueue.executeNext_ (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21) at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27 at protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7 at process._tickCallback (internal/process/next_tick.js:103:7) From: Task: Element with locator: by.binding("teacher.performance.tests.SCORE_ADDED_MSG") is not visible. at ControlFlow.wait (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2352:17) at WebDriver.wait (protractor-poc/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:712:29) at ProtractorBrowser.to.(anonymous function) as wait at [object Object].waitForElement (protractor-poc/steps/support/waitForElement.js:40:20) at [object Object].
(protractor-poc/steps/performanceSteps.js:128:14) at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9) [12:53:03] E/launcher - Process exited with error code 199
- Node Version: 5.10.1
- Protractor Version: 4.0.3
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/protractor/issues/3491, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF6jeJYGbYWjLn1nfnxFfPlJscGXj9iks5qitTKgaJpZM4Jqzok .
Can you provide a little more information on your test setup? I'm not quite sure what you mean by " now if the error is not thrown inside the promise that is returned from the step definition".
It seems like this is an issue you should raise with protractor-cucumber-framework but some more detail will help narrow it down.
As per Cucumber documentation, steps can return promises instead of using callbacks to mark that they completed.
Example step:
this.Then(/^I should see info that there are no assignments$/, function() {
this.waitForElement(this.pages.assignments.noAssignmentsMessage, 3000, 'visible'); // an error here will cause Protractor to exit
return this.expect(this.pages.assignments.getNoAssignmentsMessage())
.to.eventually.equal(this.pages.assignments.messages['no assignments']); // an error here will cause the step, and consequently the spec it's a part of, to fail
});
waitForElement is basically a wrapper for Protractor's ExpectedConditions, while expect is from chai-as-promised. With v3.3.0 of Protractor wherever in the step an error was thrown (NoSuchElement, AssertionError or any other) it only failed the spec and didn't cause the runner to exit.
This sounds like something wrong with the way that cucumber is handling exception within the tests and not necessarily protractor itself (since chai is also involved here).
I think the best next steps are to open an issue with the protractor cucumber framework. If this ends up being something with Protractor itself after resolving the issues with the framework, feel free to open another issue.
I'm going to close this; Hopefully that makes sense 😄
Well, I've conducted a bit of an investigation and it turns out uncaughtException event listener added in #3133 is to blame. Since it registers first it's fired before Cucumber's listener for the same event, which would normally handle whatever error occurred and gracefully fail the step.
Not sure what to do now... Thoughts?
How does it work for Jasmine or Mocha then? Maybe something that we can learn from
On Thu, Aug 25, 2016 at 10:28 AM, Oskar B [email protected] wrote:
Well, I've conducted a bit of an investigation and it turns out uncaughtException event listener added in #3133 https://github.com/angular/protractor/pull/3133 is to blame. Since it registers first it's fired before Cucumber's listener for the same event, which would normally handle whatever error occurred and gracefully fail the step.
Not sure what to do now... Thoughts?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/protractor/issues/3491#issuecomment-242407266, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF6jYGHgygjEU1JPwGI399Fby2aw3Kyks5qjaaPgaJpZM4Jqzok .
@calendir this still feels like an issue with the framework itself? UncaughtException should only be raised if nothing else is capturing the exception. I can't reproduce this using mocha and chai-as-promised, so it seems like there's something else going on between protractor-cucumber. If you could create a small reproducible example i'd be happy to take a look.
We can open a more targeted issue if it is indeed a problem with the way that protractor is functioning.
@NickTomlin thanks for taking the time to look at this!
I've created a quick example here. Running it and looking at how Cucumber does its thing should make the issue clear, I hope :)
+1 Having the same problem
I've raised an issue on the cucumber side of things https://github.com/cucumber/cucumber-js/issues/643 if y'all would like to chime in there. I'm still not quite clear where the breakdown is here (since Mocha seems to handle this just fine) so extra investigation would be helpful!
I'm having the same problem in protractor v4.0.10
ignoreUncaughtExceptions: true need to be set for protractor/cucumber/chai to work
@jlin412 thanks very much for your answer!! I got error 199 using cucumber.js/protractor/chai/chai-as-promised if any step fails My tests just stopped with error 199 and no result was displayed for any of following steps. No reports were generated.
Your answer resolved this!
@NickTomlin, finally is this a cucumber or protractor issue? Will it be resolved in a new release?
@jlin412 Thanks bud, that resolved my instance of WebdriverError NoSuchElementError: No element found using locator when attempting to click something with a null selector (hadn't had the selector mapped yet, but wanted to figure out what was going on).
This feels a little kludgy, but in avoiding setting that ignoreUncaughtExceptions in the protractor config, this seems to meet my need of getting around the OP suite-killing webdriver level error, while still handling an error up to the stepdef/step level callback, allowing me to fail the step in the scenario and proceed with the test suite. For some reason I was not able to get this same try/catch method working for the stepdef callback if I used it during a failureCB on the .click() promise, but I hope this maybe helps someone in the future:
this.When(/^I click on the "([^"]*)" ([a-z A-Z]+?)$/, function (objectToClick, elementType, callback) {
// Example: I click on the "Save" button
objectToClick = pageAttributes[elementType][objectToClick]; //Just a local map for DOM attribs
objectToClick = element(by.css(objectToClick));
objectToClick.isPresent()
.then(
function(presence){
if(presence == true) objectToClick.click().then(callback());
else {
try {
console.assert(presence, "Had trouble clicking the object.");
}
catch (err) {
callback(err)
}
}
});
});
@jlin412 Thank you for your answer. Works like a charm, and I had been looking for a solution everywhere!