Skip to content

Commit

Permalink
Change tests to use Internet Explore 11
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusdacoregio committed Apr 27, 2023
1 parent 2f8a63d commit f27ac24
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

package example;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
Expand All @@ -33,7 +37,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.web.htmlunit.LocalHostWebClient;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
import org.springframework.util.Assert;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -108,4 +118,34 @@ private HtmlForm findForm(HtmlPage login) {
throw new IllegalStateException("Could not resolve login form");
}

@TestConfiguration
static class WebClientConfiguration {

@Bean
public MockMvcWebClientBuilder mockMvcWebClientBuilder(MockMvc mockMvc, Environment environment) {
return MockMvcWebClientBuilder.mockMvcSetup(mockMvc).withDelegate(new InternetExplorerLocalHostWebClient(environment));
}

}

static class InternetExplorerLocalHostWebClient extends WebClient {

private final Environment environment;

public InternetExplorerLocalHostWebClient(Environment environment) {
super(BrowserVersion.INTERNET_EXPLORER);
Assert.notNull(environment, "Environment must not be null");
this.environment = environment;
}

@Override
public <P extends Page> P getPage(String url) throws IOException, FailingHttpStatusCodeException {
if (url.startsWith("/")) {
String port = this.environment.getProperty("local.server.port", "8080");
url = "http://localhost:" + port + url;
}
return super.getPage(url);
}
}

}

0 comments on commit f27ac24

Please sign in to comment.