|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -35,8 +35,8 @@ import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.mock.env.MockEnvironment;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.argThat;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.isNull;
|
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
@ -55,6 +55,9 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
|
|
|
|
|
this.webClient = webClient;
|
|
|
|
|
given(this.webClient.getOptions()).willReturn(new WebClientOptions());
|
|
|
|
|
given(this.webClient.getWebConsole()).willReturn(new WebConsole());
|
|
|
|
|
WebWindow currentWindow = mock(WebWindow.class);
|
|
|
|
|
given(currentWindow.isClosed()).willReturn(false);
|
|
|
|
|
given(this.webClient.getCurrentWindow()).willReturn(currentWindow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -80,7 +83,7 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
|
|
|
|
|
void createWithCapabilitiesWhenEnvironmentIsNullWillThrowException() {
|
|
|
|
|
Capabilities capabilities = mock(Capabilities.class);
|
|
|
|
|
given(capabilities.getBrowserName()).willReturn("htmlunit");
|
|
|
|
|
given(capabilities.getVersion()).willReturn("chrome");
|
|
|
|
|
given(capabilities.getBrowserVersion()).willReturn("chrome");
|
|
|
|
|
assertThatIllegalArgumentException()
|
|
|
|
|
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null, capabilities))
|
|
|
|
|
.withMessageContaining("Environment must not be null");
|
|
|
|
@ -91,7 +94,7 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
|
|
|
|
|
MockEnvironment environment = new MockEnvironment();
|
|
|
|
|
LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver(environment);
|
|
|
|
|
driver.get("/test");
|
|
|
|
|
verify(this.webClient).getPage(any(WebWindow.class), requestToUrl(new URL("http://localhost:8080/test")));
|
|
|
|
|
verify(this.webClient).getPage(isNull(), requestToUrl(new URL("http://localhost:8080/test")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -100,7 +103,7 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
|
|
|
|
|
environment.setProperty("local.server.port", "8181");
|
|
|
|
|
LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver(environment);
|
|
|
|
|
driver.get("/test");
|
|
|
|
|
verify(this.webClient).getPage(any(WebWindow.class), requestToUrl(new URL("http://localhost:8181/test")));
|
|
|
|
|
verify(this.webClient).getPage(isNull(), requestToUrl(new URL("http://localhost:8181/test")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private WebRequest requestToUrl(URL url) {
|
|
|
|
|