首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Play 2.5和Fluentlenium:如何关闭HtmlUnit警告

Play 2.5和Fluentlenium:如何关闭HtmlUnit警告
EN

Stack Overflow用户
提问于 2016-06-14 20:19:30
回答 1查看 258关注 0票数 0

我正在尝试使用WithBrowser 2.5的PlayFramework类编写Selenium测试。

就像这样:

代码语言:javascript
复制
public class BrowserFunctionalTest extends WithBrowser {

   @Test
   public void runInBrowser() {
      browser.goTo("/");
      assertNotNull(browser.$("title").getText());
  }
}

但是,我希望能够为至少CSS错误设置自定义错误处理程序,因为它们会垃圾邮件给我的控制台。因为它们是从鞋带来的,所以我无法摆脱它们。

我试图像这样设置记录器的日志级别:

代码语言:javascript
复制
 java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);    
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");

Fluentlenium文档告诉我重写getDefaultDriver方法,但在这里似乎不适用。而且我不能直接得到WebClient,因为没有领域的吸气器。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-15 05:16:32

当使用WithBrowser助手类时,可以重写provideBrowser来自定义TestBrowser的配置方式。还有一些其他细节,但下面的代码几乎说明了如何做到这一点:

代码语言:javascript
复制
import static  org.junit.Assert.*;

import com.gargoylesoftware.htmlunit.WebClient;
import org.junit.Test;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import play.test.Helpers;
import play.test.TestBrowser;
import play.test.WithBrowser;

public class BrowserFunctionalTest extends WithBrowser {

    // Just to make the WebClient visible at the test. Of course, this
    // could be an independent class to be reused by other tests or you
    // can create your own class that extends WithBrowser and hide all
    // the details from your tests.
    public static class CustomHtmlUnitDriver extends HtmlUnitDriver {
        @Override
        public WebClient getWebClient() {
            return super.getWebClient();
        }
    }

    @Override
    protected TestBrowser provideBrowser(int port) {
        // Here you need to create the TestBrowser for the class above.
        TestBrowser browser = Helpers.testBrowser(CustomHtmlUnitDriver.class, port);
        CustomHtmlUnitDriver driver = (CustomHtmlUnitDriver)browser.getDriver();
        WebClient client = driver.getWebClient();

        // do whatever you want with the WebClient

        return browser;
    }

    @Test
    public void runInBrowser() {
        browser.goTo("/");
        assertNotNull(browser.$("title").getText());
    }
} 

现在,由于您已经可以访问WebClient,您可以按照本讨论中的说明:

Turning HtmlUnit Warnings off

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37821376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档