From a2bed160f050c728abfda5b0ad3cce8f43dfc46d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 3 Jan 2022 09:42:41 +0100 Subject: [PATCH] Upgrade to Selenium 4.1.1 Closes gh-29237 --- .../spring-boot-dependencies/build.gradle | 2 +- .../WebMvcTestWebDriverIntegrationTests.java | 6 +++--- spring-boot-project/spring-boot-test/build.gradle | 1 + .../LocalHostWebConnectionHtmlUnitDriverTests.java | 13 ++++++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 42df274ee0..5dab92b4b7 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1549,7 +1549,7 @@ bom { ] } } - library("Selenium", "3.141.59") { + library("Selenium", "4.1.1") { group("org.seleniumhq.selenium") { modules = [ "selenium-api", diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWebDriverIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWebDriverIntegrationTests.java index 50faf940de..534fdae23a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWebDriverIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWebDriverIntegrationTests.java @@ -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. @@ -20,7 +20,7 @@ import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchWindowException; +import org.openqa.selenium.NoSuchSessionException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -59,7 +59,7 @@ class WebMvcTestWebDriverIntegrationTests { this.webDriver.get("/html"); WebElement element = this.webDriver.findElement(By.tagName("body")); assertThat(element.getText()).isEqualTo("Hello"); - assertThatExceptionOfType(NoSuchWindowException.class).isThrownBy(previousWebDriver::getWindowHandle); + assertThatExceptionOfType(NoSuchSessionException.class).isThrownBy(previousWebDriver::getWindowHandle); assertThat(previousWebDriver).isNotNull().isNotSameAs(this.webDriver); } diff --git a/spring-boot-project/spring-boot-test/build.gradle b/spring-boot-project/spring-boot-test/build.gradle index 8ce8eba2c8..b31a8ec6ce 100644 --- a/spring-boot-project/spring-boot-test/build.gradle +++ b/spring-boot-project/spring-boot-test/build.gradle @@ -45,6 +45,7 @@ dependencies { testImplementation("io.mockk:mockk") testImplementation("jakarta.json:jakarta.json-api") testImplementation("ch.qos.logback:logback-classic") + testImplementation("com.squareup.okhttp3:okhttp") testImplementation("org.apache.tomcat.embed:tomcat-embed-core") testImplementation("org.codehaus.groovy:groovy") testImplementation("org.codehaus.groovy:groovy-xml") diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java index 9272668202..2e4b3b3bff 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java @@ -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) {