Open kriegaex opened 2 years ago
Hi Alexander, the CssErrorHandler handles (mainly) errors found while parsing the css file. But this warning is a bit more different. The css is correct but HtmlUnit is not able to deal with this calc stuff and therefore reports this warning.
You can disable this using set the log level for HtmlUnit or for only the CSSStyleSheet class.
What do you think - maybe i have to change the text of the warning a bit or do you still think i should use the error handler here?
I know the best would be to support this calc stuff (and many more css thinks) but my time is limited. Maybe you like to help with stuff like this - PR's are always welcome.
OK, I think if I can programmatically define the log level for CSSStyleSheet
in a generic way, that will be fine. As HtmlUnit uses Commons Logging, actually in my Geb configuration script (which is used in multiple project, each of which might use a different logging tool) I would like to set the log level. The Commons Logging API is not very helpful in determining which logging framework is detected and used by it during runtime and then setting the level there. So how can I do that? I know this is no longer a question specific to HtmlUnit, but because you suggested setting the log level, I would like to know.
@kriegaex What rbri means it to turn off the log level within your logging framework for that class or htmlunit in general.
Basically what this log is telling you is "this part is not 100% implemented, don't rely on it's execution when asserting your page".
So you could either set the logger for com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet
to ERROR
or turn it off completely depending on the logging implementation you're using.
@rbri My personal opinion regarding this is that this should override the SilentCSSErrorHandler since it's not an error happening in CSS like it potentially would happen in a real browser but rather a limitation of the framework. On the other hand I don't even see a real use case for the 3 log levels in the CSSHandler - so one could potentially use warning
for this 🤷
@twendelmuth, I know what rbri means and what the error means. I also know how to configure a logging framework. I just wanted to find a way to avoid configuring the framework in each of my applications and do it centrally in the module where HtmlUnit gets configured. But Commons Logging being a facade without its own means of setting the log level, this seems to be impossible.
@rbri, as for whether this kind of CSS warning should be captured by the SilentCssErrorHandler
, let us take a look at the javadocs, shall we?
The "which ignores all CSS problems" made me believe that it would also capture (and suppress) warnings about limitations in HtmlUnit itself, as it is also a warning about CSS. If the javadoc would be improved in such a way as to help users understand that warnings about incomplete implementation are not captured by the handler and they need to configure their respecive logging frameworks for it, at least it would be clear. The problem from a user perspective is, however, that they use silent XY error handlers or listeners - the class names SilentCssErrorHandler
vs SilentJavaScriptErrorListener
are inconsistent here - and their test logs are still floodded with warnings they might not wish to see (like me), but HtmlUnit provides no handler or listener to suppress them and they have to silence them outside of the tool via their respective logging frameworks. While this is of course possible, it is just not nice and inconsistent with the user experience for other types of error/warning logging.
FWIW, because the module I am currently dealing with happens to be using Logback, I added this to me config file in the test resources:
<!--
Avoid excessive logging of warnings about limitations in HtmlUnit's own CSS parser,
see https://github.com/HtmlUnit/htmlunit/issues/446
-->
<logger name="com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet" level="ERROR" />
I would be happy to be able to remove that in the future, if you would kindly consider to implement a specific handler (and a silent version of it) for those kinds of warnings. 🙂
I use HtmlUnit 2.58.0 and the corresponding HtmlUnit web driver from Geb 4.1 on top of Selenium 3.141.59.
My custom
WebClient
sets aSilentCssErrorHandler
inside overriddenmodifyWebClient
. I actually was expecting this to silence log lines likein an otherwise successful test opening on https://github.com/trending, selecting the top 3 projects and opening their GH pages.