View Javadoc
1   package com.github.searls.jasmine.driver;
2   
3   import com.gargoylesoftware.htmlunit.IncorrectnessListener;
4   import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
5   import com.gargoylesoftware.htmlunit.WebClient;
6   import org.openqa.selenium.Capabilities;
7   import org.openqa.selenium.htmlunit.HtmlUnitDriver;
8   
9   /**
10   * The default web driver - overridden to tweak a few things.
11   */
12  public class QuietHtmlUnitDriver extends HtmlUnitDriver {
13  
14    private final boolean debug;
15  
16    public QuietHtmlUnitDriver(Capabilities capabilities, boolean debug) {
17      super(capabilities);
18      this.debug = debug;
19      this.setJavascriptEnabled(true);
20    }
21  
22    @Override
23    protected WebClient modifyWebClient(WebClient client) {
24      client.setAjaxController(new NicelyResynchronizingAjaxController());
25  
26      //Disables stuff like this "com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'."
27      if (!this.debug) {
28        client.setIncorrectnessListener(new IncorrectnessListener() {
29          @Override
30          public void notify(String message, Object origin) {
31          }
32        });
33      }
34      return client;
35    }
36  }