diff --git a/java/test/org/openqa/selenium/WebNetworkTest.java b/java/test/org/openqa/selenium/WebNetworkTest.java index 8036b5edce59b..3ad732b8ff6b2 100644 --- a/java/test/org/openqa/selenium/WebNetworkTest.java +++ b/java/test/org/openqa/selenium/WebNetworkTest.java @@ -22,33 +22,19 @@ import java.net.URI; import java.util.function.Predicate; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.testing.Ignore; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.drivers.Browser; class WebNetworkTest extends JupiterTestBase { private String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - - @AfterEach - public void cleanUp() { - driver.quit(); - } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canAddAuthenticationHandler() { @@ -56,13 +42,14 @@ void canAddAuthenticationHandler() { .network() .addAuthenticationHandler(new UsernameAndPassword("test", "test")); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized"); } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canAddAuthenticationHandlerWithFilter() { @@ -72,13 +59,14 @@ void canAddAuthenticationHandlerWithFilter() { .network() .addAuthenticationHandler(filter, new UsernameAndPassword("test", "test")); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized"); } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canAddMultipleAuthenticationHandlersWithFilter() { @@ -92,13 +80,14 @@ void canAddMultipleAuthenticationHandlersWithFilter() { .addAuthenticationHandler( uri -> uri.getPath().contains("test"), new UsernameAndPassword("test1", "test1")); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized"); } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canAddMultipleAuthenticationHandlersWithTheSameFilter() { @@ -112,13 +101,14 @@ void canAddMultipleAuthenticationHandlersWithTheSameFilter() { .addAuthenticationHandler( uri -> uri.getPath().contains("basicAuth"), new UsernameAndPassword("test", "test")); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized"); } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canRemoveAuthenticationHandler() { @@ -128,7 +118,7 @@ void canRemoveAuthenticationHandler() { .addAuthenticationHandler(new UsernameAndPassword("test", "test")); ((RemoteWebDriver) driver).network().removeAuthenticationHandler(id); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThatExceptionOfType(UnhandledAlertException.class) @@ -136,11 +126,12 @@ void canRemoveAuthenticationHandler() { } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canRemoveAuthenticationHandlerThatDoesNotExist() { ((RemoteWebDriver) driver).network().removeAuthenticationHandler(5); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThatExceptionOfType(UnhandledAlertException.class) @@ -148,6 +139,7 @@ void canRemoveAuthenticationHandlerThatDoesNotExist() { } @Test + @NeedsFreshDriver @Ignore(Browser.CHROME) @Ignore(Browser.EDGE) void canClearAuthenticationHandlers() { @@ -165,7 +157,7 @@ void canClearAuthenticationHandlers() { .addAuthenticationHandler(new UsernameAndPassword("test1", "test1")); ((RemoteWebDriver) driver).network().clearAuthenticationHandlers(); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThatExceptionOfType(UnhandledAlertException.class) diff --git a/java/test/org/openqa/selenium/WebScriptTest.java b/java/test/org/openqa/selenium/WebScriptTest.java index bf7bcae431b66..29522eb060e9c 100644 --- a/java/test/org/openqa/selenium/WebScriptTest.java +++ b/java/test/org/openqa/selenium/WebScriptTest.java @@ -28,43 +28,29 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.bidi.log.ConsoleLogEntry; import org.openqa.selenium.bidi.log.JavascriptLogEntry; import org.openqa.selenium.bidi.log.LogLevel; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.remote.DomMutation; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; class WebScriptTest extends JupiterTestBase { String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - - @AfterEach - public void cleanUp() { - driver.quit(); - } @Test + @NeedsFreshDriver void canAddConsoleMessageHandler() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future = new CompletableFuture<>(); long id = ((RemoteWebDriver) driver).script().addConsoleMessageHandler(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("consoleLog")).click(); @@ -81,6 +67,7 @@ void canAddConsoleMessageHandler() } @Test + @NeedsFreshDriver void canRemoveConsoleMessageHandler() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future1 = new CompletableFuture<>(); @@ -96,7 +83,7 @@ void canRemoveConsoleMessageHandler() // Removing the second consumer, so it will no longer get the console message. ((RemoteWebDriver) driver).script().removeConsoleMessageHandler(id2); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("consoleLog")).click(); @@ -113,12 +100,13 @@ void canRemoveConsoleMessageHandler() } @Test + @NeedsFreshDriver void canAddJsErrorHandler() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future = new CompletableFuture<>(); long id = ((RemoteWebDriver) driver).script().addJavaScriptErrorHandler(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -132,6 +120,7 @@ void canAddJsErrorHandler() throws ExecutionException, InterruptedException, Tim } @Test + @NeedsFreshDriver void canRemoveJsErrorHandler() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future1 = new CompletableFuture<>(); CompletableFuture future2 = new CompletableFuture<>(); @@ -146,7 +135,7 @@ void canRemoveJsErrorHandler() throws ExecutionException, InterruptedException, // Removing the second consumer, so it will no longer get the JS error. ((RemoteWebDriver) driver).script().removeJavaScriptErrorHandler(id2); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -166,6 +155,7 @@ void canRemoveJsErrorHandler() throws ExecutionException, InterruptedException, } @Test + @NeedsFreshDriver void canAddMultipleHandlers() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future1 = new CompletableFuture<>(); CompletableFuture future2 = new CompletableFuture<>(); @@ -177,7 +167,7 @@ void canAddMultipleHandlers() throws ExecutionException, InterruptedException, T long id1 = ((RemoteWebDriver) driver).script().addJavaScriptErrorHandler(consumer1); long id2 = ((RemoteWebDriver) driver).script().addJavaScriptErrorHandler(consumer2); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -193,6 +183,7 @@ void canAddMultipleHandlers() throws ExecutionException, InterruptedException, T } @Test + @NeedsFreshDriver void canAddDomMutationHandler() throws InterruptedException { AtomicReference seen = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); @@ -220,6 +211,7 @@ void canAddDomMutationHandler() throws InterruptedException { } @Test + @NeedsFreshDriver void canRemoveDomMutationHandler() throws InterruptedException { AtomicReference seen = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); @@ -247,6 +239,7 @@ void canRemoveDomMutationHandler() throws InterruptedException { } @Test + @NeedsFreshDriver void canPinScript() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future = new CompletableFuture<>(); @@ -254,7 +247,7 @@ void canPinScript() throws ExecutionException, InterruptedException, TimeoutExce long id = ((RemoteWebDriver) driver).script().addConsoleMessageHandler(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS); @@ -265,6 +258,7 @@ void canPinScript() throws ExecutionException, InterruptedException, TimeoutExce } @Test + @NeedsFreshDriver void canUnpinScript() throws ExecutionException, InterruptedException, TimeoutException { CountDownLatch latch = new CountDownLatch(2); @@ -276,7 +270,7 @@ void canUnpinScript() throws ExecutionException, InterruptedException, TimeoutEx .script() .addConsoleMessageHandler(consoleLogEntry -> latch.countDown()); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); diff --git a/java/test/org/openqa/selenium/javascript/JavaScriptTestSuite.java b/java/test/org/openqa/selenium/javascript/JavaScriptTestSuite.java index a9052a500b8a3..4e067e0ec09bb 100644 --- a/java/test/org/openqa/selenium/javascript/JavaScriptTestSuite.java +++ b/java/test/org/openqa/selenium/javascript/JavaScriptTestSuite.java @@ -30,14 +30,11 @@ import java.util.function.Function; import java.util.function.Supplier; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.openqa.selenium.WebDriver; import org.openqa.selenium.build.InProject; import org.openqa.selenium.environment.GlobalTestEnvironment; -import org.openqa.selenium.environment.InProcessTestEnvironment; -import org.openqa.selenium.environment.TestEnvironment; import org.openqa.selenium.environment.webserver.AppServer; import org.openqa.selenium.testing.drivers.WebDriverBuilder; @@ -48,8 +45,6 @@ class JavaScriptTestSuite { private final long timeout; - private TestEnvironment testEnvironment; - public JavaScriptTestSuite() { this.timeout = Math.max(0, Long.getLong("js.test.timeout", 0)); this.driverSupplier = new DriverSupplier(); @@ -59,16 +54,8 @@ private static boolean isBazel() { return InProject.findRunfilesRoot() != null; } - @BeforeEach - public void setup() { - testEnvironment = GlobalTestEnvironment.getOrCreate(InProcessTestEnvironment::new); - } - @AfterEach public void teardown() throws IOException { - if (testEnvironment != null) { - testEnvironment.stop(); - } if (driverSupplier != null) { ((Closeable) driverSupplier).close(); }