eclipse webdriver API:如何禁用详细的错误消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3500091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:00:56  来源:igfitidea点击:

webdriver API: how to disable verbose error messages?

javaeclipsewebdriver

提问by KJW

Running the example source at

运行示例源代码

http://code.google.com/p/selenium/wiki/GettingStarted

http://code.google.com/p/selenium/wiki/GettingStarted

It runs successfully, however Eclipse throws bunch of WARNING messages. How Can I disable this from displaying ? All I really need is the last line Page title is: Cheese! - Google Search

它运行成功,但是 Eclipse 会抛出一堆 WARNING 消息。如何禁用它的显示?我真正需要的是最后一行Page title is: Cheese! - Google Search

17-Aug-2010 12:07:00 AM com.gargoylesoftware.htmlunit.util.StringUtils parseHttpDate
WARNING: Unable to parse date: -1
17-Aug-2010 12:07:00 AM com.gargoylesoftware.htmlunit.util.StringUtils parseHttpDate
WARNING: Unable to parse date: -1
17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: null [1:4686] Error in style rule. Invalid token "*". Was expecting one of: <S>, "}", ";", <IDENT>.
17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: null [1:4686] Ignoring the following declarations in this rule.
17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: null [1:6505] Error in expression. Invalid token ";". Was expecting one of: <S>, <PLUS>, "-", <HASH>, <STRING>, <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
Page title is: Cheese! - Google Search

回答by James

The answer given by zloiadun didn't work here, instead I had to use,

zloiadun 给出的答案在这里不起作用,而是我不得不使用,

Logger logger = Logger.getLogger ("");
logger.setLevel (Level.OFF);

.. changing the getLogger( .. ) and level as needed.

.. 根据需要更改 getLogger( .. ) 和级别。

回答by Saint

Though none of these things worked for me, I found that I could shut HTMLUnit up by making a custom errorhandler... this is kinda cheesy... but it gives you excellent control should you need it:

虽然这些东西都不适合我,但我发现我可以通过创建自定义错误处理程序来关闭 HTMLUnit ......这有点俗气......但是如果你需要它,它可以为你提供出色的控制:

        webClient.setCssErrorHandler(new ErrorHandler() {
        //Saint
        @Override
        public void warning(CSSParseException arg0) throws CSSException {
            // stare blankly

        }

        @Override
        public void fatalError(CSSParseException arg0) throws CSSException {
            // twiddle thumbs

        }

        @Override
        public void error(CSSParseException arg0) throws CSSException {
            // drool on shirt

        }
    });

回答by Sebastian Saip

As discussed here: Can't turn off HtmlUnit logging messages

如此处所讨论:无法关闭 HtmlUnit 日志消息

The following code worked best for me:

以下代码最适合我:

static {
    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);
}

回答by Sotomajor

Setting the property helps:

设置属性有助于:

log4j.logger.com.gargoylesoftware.htmlunit.DefaultCssErrorHandler=ERROR

log4j.logger.com.gargoylesoftware.htmlunit.DefaultCssErrorHandler=ERROR

I did it in logging.propertiesand piece of my build.xml, for instance:

我在logging.properties和我的 build.xml 中做到了,例如:

<target name="selenium">
    <junit fork="yes" haltonfailure="yes">
        <sysproperty key="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" />
        ...
    </junit>
</target>

回答by Sergii Pozharov

HtmlUnit uses the Commons Logging. You can refer herefor more details.

HtmlUnit 使用 Commons Logging。你可以参考这里了解更多详情。

As quick hint, you can disable warnings by setting the following system property:

作为快速提示,您可以通过设置以下系统属性来禁用警告:

System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");