0

WithBrowserPlayFramework 2.5 のクラスを使用して Selenium テストを作成しようとしています。

このようなもの:

public class BrowserFunctionalTest extends WithBrowser {

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

ただし、コンソールにスパムが送信されるため、少なくとも CSS エラーに対してカスタム エラー ハンドラを設定できるようにしたいと考えています。そして、それらはブーストラップから来ているので、私はそれらを取り除くことはできません.

次のようにロガーのログレベルを設定しようとしました:

 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 を直接手に入れることはできません。

4

1 に答える 1

2

WithBrowserヘルパー クラスを使用する場合、オーバーライドprovideBrowserして の構成方法をカスタマイズできTestBrowserます。他にもいくつかの詳細がありますが、以下のコードはその方法をほとんど示しています。

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、このディスカッションの指示に従うことができます。

HtmlUnit の警告をオフにする

于 2016-06-15T05:16:32.273 に答える