Search in sources :

Example 1 with HttpWebConnection

use of com.gargoylesoftware.htmlunit.HttpWebConnection in project saga by timurstrekalov.

the class WebClientFactory method newInstance.

// New version allows for creation of web drivers without the need for a config object
// which may not be readily available if the driver is created by third-party code.
public static WebClient newInstance(final BrowserVersion version) {
    final WebClient client = new WebClient(version) {

        @Override
        public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
            return new WebResponseProxy(super.loadWebResponse(webRequest));
        }
    };
    client.setIncorrectnessListener(quietIncorrectnessListener);
    client.setJavaScriptErrorListener(loggingJsErrorListener);
    client.setHTMLParserListener(quietHtmlParserListener);
    client.setCssErrorHandler(quietCssErrorHandler);
    client.getOptions().setJavaScriptEnabled(true);
    client.setAjaxController(new NicelyResynchronizingAjaxController());
    client.getOptions().setThrowExceptionOnScriptError(false);
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    client.getOptions().setPrintContentOnFailingStatusCode(false);
    client.setWebConnection(new HttpWebConnection(client) {

        @Override
        protected WebResponse newWebResponseInstance(final WebResponseData responseData, final long loadTime, final WebRequest request) {
            return new WebResponseProxy(super.newWebResponseInstance(responseData, loadTime, request));
        }
    });
    return client;
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) NicelyResynchronizingAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController) HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) WebResponseData(com.gargoylesoftware.htmlunit.WebResponseData) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 2 with HttpWebConnection

use of com.gargoylesoftware.htmlunit.HttpWebConnection in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method verifyExampleInClassLevelJavadoc.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void verifyExampleInClassLevelJavadoc() throws Exception {
    WebClient webClient = new WebClient();
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build();
    MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient);
    WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
    WebConnection httpConnection = new HttpWebConnection(webClient);
    webClient.setWebConnection(new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection)));
    Page page = webClient.getPage("https://code.jquery.com/jquery-1.11.0.min.js");
    assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
    assertThat(page.getWebResponse().getContentAsString()).isNotEmpty();
}
Also used : HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) WebConnection(com.gargoylesoftware.htmlunit.WebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Aggregations

HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)1 Page (com.gargoylesoftware.htmlunit.Page)1 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)1 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 WebResponseData (com.gargoylesoftware.htmlunit.WebResponseData)1 Test (org.junit.jupiter.api.Test)1 EnabledForTestGroups (org.springframework.core.testfixture.EnabledForTestGroups)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 DelegateWebConnection (org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection)1