spring-test-mvc-htmlunit

org.springframework.test.web.servlet.htmlunit.webdriver
Class MockMvcHtmlUnitDriver

java.lang.Object
  extended by org.openqa.selenium.htmlunit.HtmlUnitDriver
      extended by org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriver
All Implemented Interfaces:
org.openqa.selenium.HasCapabilities, org.openqa.selenium.interactions.HasInputDevices, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.SearchContext, org.openqa.selenium.WebDriver

public final class MockMvcHtmlUnitDriver
extends org.openqa.selenium.htmlunit.HtmlUnitDriver

Allows running tests off line by utilizing Spring's MockMvc to bridge between a request and a response. By doing this we are able to avoid making any HTTP calls when our tests are running. This implies we do not need to start a web container to run our tests.

Example usage can be seen below:

Instantiate with WebApplicationContext

 WebApplicationContext context = ...
 MockHtmlUnitDriver driver = new MockHtmlUnitDriver(context, true);

 ... use driver as you would HtmlUnitDriver ...
 

Instantiate with MockMvc

 MockMvc mockMvc = ...
 MockHtmlUnitDriver driver = new MockHtmlUnitDriver(mockMvc, true);

 ... use driver as you would HtmlUnitDriver ...
 

The only reason for this class is in order to customize the WebConnection used by HtmlUnitDriver. We cannot use a simple bean methods since there are no accessor methods for WebClient or the WebClient's underlying WebConnection. The only means to update the WebConnection is to override the modifyWebClient(WebClient) method. Hence for the existence of this class.

Author:
Rob Winch
See Also:
MockMvc, MockMvcWebConnection

Nested Class Summary
 
Nested classes/interfaces inherited from class org.openqa.selenium.htmlunit.HtmlUnitDriver
org.openqa.selenium.htmlunit.HtmlUnitDriver.HtmlUnitWindow, org.openqa.selenium.htmlunit.HtmlUnitDriver.JavaScriptResultsCollection
 
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
 
Field Summary
 
Fields inherited from class org.openqa.selenium.htmlunit.HtmlUnitDriver
INVALIDSELECTIONERROR, INVALIDXPATHERROR
 
Constructor Summary
MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc)
           
MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc, boolean enableJavascript)
           
MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc, com.gargoylesoftware.htmlunit.BrowserVersion version)
           
MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc, org.openqa.selenium.Capabilities capabilities)
           
MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext)
           
MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext, boolean enableJavascript)
           
MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext, com.gargoylesoftware.htmlunit.BrowserVersion version)
           
MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext, org.openqa.selenium.Capabilities capabilities)
           
 
Method Summary
protected  com.gargoylesoftware.htmlunit.WebClient modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
           
 
Methods inherited from class org.openqa.selenium.htmlunit.HtmlUnitDriver
assertElementNotStale, close, executeAsyncScript, executeScript, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, get, getCapabilities, getCurrentUrl, getCurrentWindow, getKeyboard, getMouse, getPageSource, getTitle, getWebClient, getWindowHandle, getWindowHandles, implicitlyWaitFor, isJavascriptEnabled, lastPage, manage, navigate, newHtmlUnitWebElement, newWebClient, pickWindow, quit, setAutoProxy, setHTTPProxy, setJavascriptEnabled, setProxy, setProxySettings, setSocksProxy, setSocksProxy, switchTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext,
                             boolean enableJavascript)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext,
                             com.gargoylesoftware.htmlunit.BrowserVersion version)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.web.context.WebApplicationContext webContext,
                             org.openqa.selenium.Capabilities capabilities)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc,
                             boolean enableJavascript)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc,
                             com.gargoylesoftware.htmlunit.BrowserVersion version)

MockMvcHtmlUnitDriver

public MockMvcHtmlUnitDriver(org.springframework.test.web.servlet.MockMvc mockMvc,
                             org.openqa.selenium.Capabilities capabilities)
Method Detail

modifyWebClient

protected com.gargoylesoftware.htmlunit.WebClient modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
Overrides:
modifyWebClient in class org.openqa.selenium.htmlunit.HtmlUnitDriver

spring-test-mvc-htmlunit