-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console errors and warning plugin #1916
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/. If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits. Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name. |
*/ | ||
ConsolePlugin.logMessages = function (warnings, errors) { | ||
warnings.map(function (warning) { | ||
console.error(warning.level.name + ': ' + warning.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "console.warn" here?
This looks handy to me. We do something similar with scraping through the browser logs. I'm also not entirely confident about the In my experience Firefox browser often spits out a pile of odd/useless log messages at startup, so I need to suppress the first batch of messages. (Otherwise the first test gets blamed for a bunch of stuff it didn't do.) And, I also have a list of messages that I'm not interested in seeing from Firefox. (We see a lot of "Ruleset ignored due to bad selector" messages, which is probably our app). So, it might be worth adding the ability to provide the plugin with a list of messages to ignore. |
I said this above, but I know that 'comments on outdated changes' get hard to see, so copying: It's super confusing, but Protractor actually uses both q and the webdriver promises. I think it's OK to use q in this situation, because it has no need to sync up with the webdriver promises - and it's actually probably safer, because it can't accidentally interfere with the webdriver control flow. |
var testOut = {failedCount: 0, specResults: []}; | ||
|
||
/** | ||
* This plugin scans the log after each test and can fail on error and warning messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify that it scans the 'browser log'
Thanks, I think this is generally useful and should definitely be included! I've added a couple comments about the output and some general style nitpicks, could you take a look at those? |
Thanks for the great feedback guys. Will get the updates in asap |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
*/ | ||
ConsolePlugin.parseLog = function(config) { | ||
var self = this; | ||
var deferred = q.defer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this deferred
. Just return the promise you're currently resolving it inside. That is:
return this.getBrowserLog().then(function(log) {
...
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea will give it a shot
testOut.failedCount += (warnings.length > 0 && failOnWarning) ? 1 : 0; | ||
testOut.failedCount += (errors.length > 0 && failOnError) ? 1 : 0; | ||
|
||
if(testOut.failedCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to output the log regardless don't you?
Nice! I'll merge this in later today |
Awesome and thanks for the help |
Merged in at 0351a10 |
Curious if you will be adding documentation for this plugin to the plugin docs. Also does this work with all browsers protractor works with? |
Good point James! I'll add documentation ASAP. Not sure if Travis automatically tested this in all browsers, but I imagine that it did and everything works fine. |
Thank you very much for the feature. From what I understand, the plugin would not work on Internet Explorer since I've done smth similar before and I had to skip IE, see Handling Unknown Errors in protractor. |
Also How can I get hold of the browser's console? section of the FAQ should be updated and mention the new |
Hi Alex. That's interesting to know that it doesn't work on Internet explorer. I did not realize that. In our company we don't currently run protractor tests against ie, only chrome and firefox.I had a lot of headaches trying to make the tests run stable on ie. Hopefully support will be added soon for i.e. I could put in the suggested fix you mentioned here - http://stackoverflow.com/questions/27587571/handling-unknown-errors-in-protractor But is there any point as you could just leave the plugin out of your internet explorer config?. |
@el-davo thanks for the quick response. For us it is not a big deal too at the current project, since currently we are not automating IE, but we'll do that in the future - as a workaround, we can apply the fix suggested in that SO topic, or have a separate config. We should at least document that the plugin would not work on IE, or implicitly skip checking the logs if running against IE, or may be issue a warning..what do you think? Also, let me know if I should create a separate issue for the following suggestion: is it possible to group the console errors and warnings that have the same text and stack trace? At the moment the test output I get has about a hundred repeated stack trace blocks, since every test I run detects the same error message on the console. Hope it is clear what I'm trying to say. Thanks. |
Hi Alex I like that suggestion of not having the same stack traces. No need to create a seperate issue. I can look into that in the next few days. Maybe we can do what they do in the chrome dev tools and have a counter that increases if the message is the same. For example if i have an error WARNING (2 times) this is a warning message, line 32, column 4 Will try and add a readme also explicitly stating that ie. is a no go for now :) |
From what i could see all tests fail in the event of a console error. Don't you think would be great to check console changes after each test in order to find out which interaction caused the error? Right now we have a website with a lot of fields not localized yet so we have a lot of INFO entries in console. It gets so huge that I'm getting Java heap space errors when the plugin tries to print it. Maybe a parameter to avoid the print...
|
My first attempt at writing a plugin. Its usage is meant to fail when there are errors and warnings on the console of the browser.. Let me know what you guys think