HtmlUnit / htmlunit

HtmlUnit is a "GUI-Less browser for Java programs".
https://www.htmlunit.org
Apache License 2.0
863 stars 171 forks source link

"CSSValue X has to be a Y value" is logged despite using SilentCssErrorHandler #446

Open kriegaex opened 2 years ago

kriegaex commented 2 years ago

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 a SilentCssErrorHandler inside overridden modifyWebClient. I actually was expecting this to silence log lines like

13:28:11.582 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.587 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.587 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.587 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.597 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.599 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.599 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.599 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.603 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.603 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.604 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.604 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.607 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.607 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.607 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.608 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.610 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.610 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.610 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.610 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.616 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.616 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.617 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.617 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.641 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(544px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.641 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(768px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.642 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue 'calc(1012px - 0.02px)' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.
13:28:11.642 [main] WARN  c.g.h.j.host.css.CSSStyleSheet - CSSValue '0\0 ' has to be a 'px', 'em', '%', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.

in an otherwise successful test opening on https://github.com/trending, selecting the top 3 projects and opening their GH pages.

rbri commented 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.

kriegaex commented 2 years ago

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.

twendelmuth commented 2 years ago

@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 🤷

kriegaex commented 2 years ago

@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?

https://github.com/HtmlUnit/htmlunit/blob/d44dc2fc7610567c76232a96447f5b1d003073b4/src/main/java/com/gargoylesoftware/htmlunit/SilentCssErrorHandler.java#L23-L29

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.

kriegaex commented 2 years ago

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. 🙂