From 6154ce74a76abd32a467d4a5a93e665ecc0762b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Fri, 1 Nov 2024 19:50:12 +0100 Subject: [PATCH] [java] use common annotations in BiDi tests --- .../org/openqa/selenium/bidi/BiDiTest.java | 24 +------ .../bidi/browser/BrowserCommandsTest.java | 20 ++---- .../BrowsingContextInspectorTest.java | 46 +++++-------- .../browsingcontext/BrowsingContextTest.java | 65 ++++++++++-------- .../bidi/browsingcontext/LocateNodesTest.java | 30 +++------ .../bidi/input/ReleaseCommandTest.java | 10 +-- .../bidi/input/SetFilesCommandTest.java | 11 ++-- .../selenium/bidi/log/LogInspectorTest.java | 66 +++++++++---------- .../network/AddInterceptParametersTest.java | 28 ++------ .../bidi/network/NetworkCommandsTest.java | 48 ++++++-------- .../bidi/network/NetworkEventsTest.java | 39 ++++------- .../script/CallFunctionParameterTest.java | 36 +++++----- .../bidi/script/EvaluateParametersTest.java | 28 +++----- .../bidi/script/ScriptCommandsTest.java | 55 +++++++++------- .../bidi/script/ScriptEventsTest.java | 26 ++------ .../grid/router/RemoteWebDriverBiDiTest.java | 17 +++-- 16 files changed, 223 insertions(+), 326 deletions(-) diff --git a/java/test/org/openqa/selenium/bidi/BiDiTest.java b/java/test/org/openqa/selenium/bidi/BiDiTest.java index f2c34b2fc1b85..26212c80eefcd 100644 --- a/java/test/org/openqa/selenium/bidi/BiDiTest.java +++ b/java/test/org/openqa/selenium/bidi/BiDiTest.java @@ -18,15 +18,12 @@ package org.openqa.selenium.bidi; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.EDGE; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.bidi.browsingcontext.BrowsingContext; @@ -35,24 +32,17 @@ import org.openqa.selenium.bidi.log.JavascriptLogEntry; import org.openqa.selenium.bidi.log.LogLevel; import org.openqa.selenium.bidi.module.LogInspector; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; class BiDiTest extends JupiterTestBase { String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test @NotYetImplemented(EDGE) + @NeedsFreshDriver void canNavigateAndListenToErrors() throws ExecutionException, InterruptedException, TimeoutException { try (org.openqa.selenium.bidi.module.LogInspector logInspector = new LogInspector(driver)) { @@ -61,7 +51,7 @@ void canNavigateAndListenToErrors() BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); NavigationResult info = browsingContext.navigate(page, ReadinessState.COMPLETE); // If navigation was successful, we expect both the url and navigation id to be set @@ -78,12 +68,4 @@ void canNavigateAndListenToErrors() assertThat(logEntry.getLevel()).isEqualTo(LogLevel.ERROR); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java b/java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java index f196b3e6c2b18..b35b9d4c14f45 100644 --- a/java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java +++ b/java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java @@ -18,31 +18,25 @@ package org.openqa.selenium.bidi.browser; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; -import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.List; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.bidi.module.Browser; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; class BrowserCommandsTest extends JupiterTestBase { - private AppServer server; private Browser browser; @BeforeEach public void setUp() { - server = new NettyAppServer(); - server.start(); browser = new Browser(driver); } @Test + @NeedsFreshDriver void canCreateAUserContext() { String userContext = browser.createUserContext(); @@ -52,6 +46,7 @@ void canCreateAUserContext() { } @Test + @NeedsFreshDriver void canGetUserContexts() { String userContext1 = browser.createUserContext(); String userContext2 = browser.createUserContext(); @@ -64,6 +59,7 @@ void canGetUserContexts() { } @Test + @NeedsFreshDriver void canRemoveUserContext() { String userContext1 = browser.createUserContext(); String userContext2 = browser.createUserContext(); @@ -79,12 +75,4 @@ void canRemoveUserContext() { browser.removeUserContext(userContext1); } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java index a92110c96eb15..adab1e9305c1c 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java @@ -18,34 +18,22 @@ package org.openqa.selenium.bidi.browsingcontext; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; -import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.module.BrowsingContextInspector; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; class BrowsingContextInspectorTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - @Test + @NeedsFreshDriver void canListenToWindowBrowsingContextCreatedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -66,6 +54,7 @@ void canListenToWindowBrowsingContextCreatedEvent() } @Test + @NeedsFreshDriver void canListenToBrowsingContextDestroyedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -87,6 +76,7 @@ void canListenToBrowsingContextDestroyedEvent() } @Test + @NeedsFreshDriver void canListenToTabBrowsingContextCreatedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -106,6 +96,7 @@ void canListenToTabBrowsingContextCreatedEvent() } @Test + @NeedsFreshDriver void canListenToDomContentLoadedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -113,7 +104,7 @@ void canListenToDomContentLoadedEvent() inspector.onDomContentLoaded(future::complete); BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); - context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); + context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS); assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId()); @@ -122,6 +113,7 @@ void canListenToDomContentLoadedEvent() } @Test + @NeedsFreshDriver void canListenToBrowsingContextLoadedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -129,7 +121,7 @@ void canListenToBrowsingContextLoadedEvent() inspector.onBrowsingContextLoaded(future::complete); BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); - context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); + context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS); assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId()); @@ -138,6 +130,7 @@ void canListenToBrowsingContextLoadedEvent() } @Test + @NeedsFreshDriver void canListenToNavigationStartedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -145,7 +138,7 @@ void canListenToNavigationStartedEvent() inspector.onNavigationStarted(future::complete); BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); - context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); + context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE); NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS); assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId()); @@ -154,18 +147,19 @@ void canListenToNavigationStartedEvent() } @Test + @NeedsFreshDriver void canListenToFragmentNavigatedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); - context.navigate(server.whereIs("/linked_image.html"), ReadinessState.COMPLETE); + context.navigate(appServer.whereIs("/linked_image.html"), ReadinessState.COMPLETE); inspector.onFragmentNavigated(future::complete); context.navigate( - server.whereIs("/linked_image.html#linkToAnchorOnThisPage"), ReadinessState.COMPLETE); + appServer.whereIs("/linked_image.html#linkToAnchorOnThisPage"), ReadinessState.COMPLETE); NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS); assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId()); @@ -174,6 +168,7 @@ void canListenToFragmentNavigatedEvent() } @Test + @NeedsFreshDriver void canListenToUserPromptOpenedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) { @@ -182,7 +177,7 @@ void canListenToUserPromptOpenedEvent() BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); inspector.onUserPromptOpened(future::complete); - driver.get(server.whereIs("/alerts.html")); + driver.get(appServer.whereIs("/alerts.html")); driver.findElement(By.id("alert")).click(); @@ -193,6 +188,7 @@ void canListenToUserPromptOpenedEvent() } @Test + @NeedsFreshDriver // TODO: This test is flaky for comparing the browsing context id for Chrome and Edge. Fix flaky // test. void canListenToUserPromptClosedEvent() @@ -203,7 +199,7 @@ void canListenToUserPromptClosedEvent() BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); inspector.onUserPromptClosed(future::complete); - driver.get(server.whereIs("/alerts.html")); + driver.get(appServer.whereIs("/alerts.html")); driver.findElement(By.id("prompt")).click(); @@ -216,12 +212,4 @@ void canListenToUserPromptClosedEvent() assertThat(userPromptClosed.getAccepted()).isTrue(); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java index af26b601e8551..44e0e0ed8b905 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java @@ -22,11 +22,8 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs; import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated; -import static org.openqa.selenium.testing.Safely.safelyCall; import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -35,24 +32,16 @@ import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.BiDiException; import org.openqa.selenium.bidi.module.Browser; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.environment.webserver.Page; import org.openqa.selenium.print.PrintOptions; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; class BrowsingContextTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - @Test + @NeedsFreshDriver void canCreateABrowsingContextForGivenId() { String id = driver.getWindowHandle(); BrowsingContext browsingContext = new BrowsingContext(driver, id); @@ -60,12 +49,14 @@ void canCreateABrowsingContextForGivenId() { } @Test + @NeedsFreshDriver void canCreateAWindow() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.WINDOW); assertThat(browsingContext.getId()).isNotEmpty(); } @Test + @NeedsFreshDriver void canCreateAWindowWithAReferenceContext() { BrowsingContext browsingContext = new BrowsingContext( @@ -76,12 +67,14 @@ void canCreateAWindowWithAReferenceContext() { } @Test + @NeedsFreshDriver void canCreateATab() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); assertThat(browsingContext.getId()).isNotEmpty(); } @Test + @NeedsFreshDriver void canCreateATabWithAReferenceContext() { BrowsingContext browsingContext = new BrowsingContext( @@ -91,6 +84,7 @@ void canCreateATabWithAReferenceContext() { } @Test + @NeedsFreshDriver void canCreateAContextWithAllParameters() { Browser browser = new Browser(driver); String userContextId = browser.createUserContext(); @@ -107,10 +101,11 @@ void canCreateAContextWithAllParameters() { } @Test + @NeedsFreshDriver void canNavigateToAUrl() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); - String url = server.whereIs("/bidi/logEntryAdded.html"); + String url = appServer.whereIs("/bidi/logEntryAdded.html"); NavigationResult info = browsingContext.navigate(url); assertThat(browsingContext.getId()).isNotEmpty(); @@ -118,10 +113,11 @@ void canNavigateToAUrl() { } @Test + @NeedsFreshDriver void canNavigateToAUrlWithReadinessState() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); - String url = server.whereIs("/bidi/logEntryAdded.html"); + String url = appServer.whereIs("/bidi/logEntryAdded.html"); NavigationResult info = browsingContext.navigate(url, ReadinessState.COMPLETE); assertThat(browsingContext.getId()).isNotEmpty(); @@ -129,11 +125,12 @@ void canNavigateToAUrlWithReadinessState() { } @Test + @NeedsFreshDriver void canGetTreeWithAChild() { String referenceContextId = driver.getWindowHandle(); BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId); - String url = server.whereIs("iframes.html"); + String url = appServer.whereIs("iframes.html"); parentWindow.navigate(url, ReadinessState.COMPLETE); @@ -147,11 +144,12 @@ void canGetTreeWithAChild() { } @Test + @NeedsFreshDriver void canGetTreeWithDepth() { String referenceContextId = driver.getWindowHandle(); BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId); - String url = server.whereIs("iframes.html"); + String url = appServer.whereIs("iframes.html"); parentWindow.navigate(url, ReadinessState.COMPLETE); @@ -164,6 +162,7 @@ void canGetTreeWithDepth() { } @Test + @NeedsFreshDriver void canGetAllTopLevelContexts() { BrowsingContext window1 = new BrowsingContext(driver, driver.getWindowHandle()); BrowsingContext window2 = new BrowsingContext(driver, WindowType.WINDOW); @@ -174,6 +173,7 @@ void canGetAllTopLevelContexts() { } @Test + @NeedsFreshDriver void canCloseAWindow() { BrowsingContext window1 = new BrowsingContext(driver, WindowType.WINDOW); BrowsingContext window2 = new BrowsingContext(driver, WindowType.WINDOW); @@ -184,6 +184,7 @@ void canCloseAWindow() { } @Test + @NeedsFreshDriver void canCloseATab() { BrowsingContext tab1 = new BrowsingContext(driver, WindowType.TAB); BrowsingContext tab2 = new BrowsingContext(driver, WindowType.TAB); @@ -194,6 +195,7 @@ void canCloseATab() { } @Test + @NeedsFreshDriver void canActivateABrowsingContext() { BrowsingContext window1 = new BrowsingContext(driver, driver.getWindowHandle()); // 2nd window is focused @@ -211,10 +213,11 @@ void canActivateABrowsingContext() { // Refer: https://github.com/w3c/webdriver-bidi/issues/187 @Test + @NeedsFreshDriver void canReloadABrowsingContext() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); - String url = server.whereIs("/bidi/logEntryAdded.html"); + String url = appServer.whereIs("/bidi/logEntryAdded.html"); browsingContext.navigate(url, ReadinessState.COMPLETE); NavigationResult reloadInfo = browsingContext.reload(); @@ -223,10 +226,11 @@ void canReloadABrowsingContext() { } @Test + @NeedsFreshDriver void canReloadWithReadinessState() { BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); - String url = server.whereIs("/bidi/logEntryAdded.html"); + String url = appServer.whereIs("/bidi/logEntryAdded.html"); browsingContext.navigate(url, ReadinessState.COMPLETE); NavigationResult reloadInfo = browsingContext.reload(ReadinessState.COMPLETE); @@ -236,6 +240,7 @@ void canReloadWithReadinessState() { } @Test + @NeedsFreshDriver void canHandleUserPrompt() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -250,6 +255,7 @@ void canHandleUserPrompt() { } @Test + @NeedsFreshDriver void canAcceptUserPrompt() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -264,6 +270,7 @@ void canAcceptUserPrompt() { } @Test + @NeedsFreshDriver void canDismissUserPrompt() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -278,6 +285,7 @@ void canDismissUserPrompt() { } @Test + @NeedsFreshDriver void canPassUserTextToUserPrompt() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -294,6 +302,7 @@ void canPassUserTextToUserPrompt() { } @Test + @NeedsFreshDriver void canAcceptUserPromptWithUserText() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -310,6 +319,7 @@ void canAcceptUserPromptWithUserText() { } @Test + @NeedsFreshDriver void canDismissUserPromptWithUserText() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -333,6 +343,7 @@ void canDismissUserPromptWithUserText() { // TODO: A potential solution can be replicating classic WebDriver screenshot tests. // Meanwhile, trusting the browsers to do the right thing. @Test + @NeedsFreshDriver void canCaptureScreenshot() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -344,6 +355,7 @@ void canCaptureScreenshot() { } @Test + @NeedsFreshDriver void canCaptureScreenshotWithAllParameters() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -369,6 +381,7 @@ void canCaptureScreenshotWithAllParameters() { } @Test + @NeedsFreshDriver void canCaptureScreenshotOfViewport() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -385,6 +398,7 @@ void canCaptureScreenshotOfViewport() { } @Test + @NeedsFreshDriver void canCaptureElementScreenshot() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -399,6 +413,7 @@ void canCaptureElementScreenshot() { } @Test + @NeedsFreshDriver void canSetViewport() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); driver.get(appServer.whereIs("formPage.html")); @@ -415,6 +430,7 @@ void canSetViewport() { } @Test + @NeedsFreshDriver void canSetViewportWithDevicePixelRatio() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); driver.get(appServer.whereIs("formPage.html")); @@ -436,6 +452,7 @@ void canSetViewportWithDevicePixelRatio() { } @Test + @NeedsFreshDriver void canPrintPage() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -453,6 +470,7 @@ void canPrintPage() { } @Test + @NeedsFreshDriver void canNavigateBackInTheBrowserHistory() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE); @@ -465,6 +483,7 @@ void canNavigateBackInTheBrowserHistory() { } @Test + @NeedsFreshDriver void canNavigateForwardInTheBrowserHistory() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE); @@ -506,12 +525,4 @@ private String promptPage() { private boolean getDocumentFocus() { return (boolean) ((JavascriptExecutor) driver).executeScript("return document.hasFocus();"); } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java b/java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java index c1f967ebc36ba..611f3c18ba086 100644 --- a/java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java +++ b/java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java @@ -17,15 +17,12 @@ package org.openqa.selenium.bidi.browsingcontext; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.bidi.module.Script; import org.openqa.selenium.bidi.script.EvaluateResult; @@ -35,21 +32,14 @@ import org.openqa.selenium.bidi.script.RemoteReference; import org.openqa.selenium.bidi.script.RemoteValue; import org.openqa.selenium.bidi.script.ResultOwnership; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; public class LocateNodesTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver void canLocateNodes() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -63,6 +53,7 @@ void canLocateNodes() { } @Test + @NeedsFreshDriver void canLocateNodesWithJustLocator() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -74,6 +65,7 @@ void canLocateNodesWithJustLocator() { } @Test + @NeedsFreshDriver void canLocateNode() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -85,6 +77,7 @@ void canLocateNode() { } @Test + @NeedsFreshDriver void canLocateNodesWithCSSLocator() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -107,6 +100,7 @@ void canLocateNodesWithCSSLocator() { } @Test + @NeedsFreshDriver void canLocateNodesWithXPathLocator() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -129,6 +123,7 @@ void canLocateNodesWithXPathLocator() { } @Test + @NeedsFreshDriver @NotYetImplemented(FIREFOX) void canLocateNodesWithInnerText() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -148,6 +143,7 @@ void canLocateNodesWithInnerText() { } @Test + @NeedsFreshDriver void canLocateNodesWithMaxNodeCount() { BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); assertThat(browsingContext.getId()).isNotEmpty(); @@ -162,6 +158,7 @@ void canLocateNodesWithMaxNodeCount() { } @Test + @NeedsFreshDriver void canLocateNodesGivenStartNodes() { String handle = driver.getWindowHandle(); BrowsingContext browsingContext = new BrowsingContext(driver, handle); @@ -200,6 +197,7 @@ void canLocateNodesGivenStartNodes() { } @Test + @NeedsFreshDriver void canLocateNodesInAGivenSandbox() { String sandbox = "sandbox"; BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle()); @@ -241,12 +239,4 @@ void canLocateNodesInAGivenSandbox() { String sharedId = (String) ((RemoteValue) sharedIdMap.get("sharedId")).getValue().get(); assertThat(sharedId).isEqualTo(nodeId); } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/input/ReleaseCommandTest.java b/java/test/org/openqa/selenium/bidi/input/ReleaseCommandTest.java index f973be888bd0c..44555f8118544 100644 --- a/java/test/org/openqa/selenium/bidi/input/ReleaseCommandTest.java +++ b/java/test/org/openqa/selenium/bidi/input/ReleaseCommandTest.java @@ -27,29 +27,25 @@ import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; import org.openqa.selenium.bidi.module.Input; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; public class ReleaseCommandTest extends JupiterTestBase { private Input input; private String windowHandle; - private AppServer server; - @BeforeEach public void setUp() { windowHandle = driver.getWindowHandle(); input = new Input(driver); - server = new NettyAppServer(); - server.start(); } @Test + @NeedsFreshDriver public void testReleaseInBrowsingContext() { - driver.get(server.whereIs("/bidi/release_action.html")); + driver.get(appServer.whereIs("/bidi/release_action.html")); WebElement inputTextBox = driver.findElement(By.id("keys")); diff --git a/java/test/org/openqa/selenium/bidi/input/SetFilesCommandTest.java b/java/test/org/openqa/selenium/bidi/input/SetFilesCommandTest.java index 87a9e5e7d8069..0439fd7329f59 100644 --- a/java/test/org/openqa/selenium/bidi/input/SetFilesCommandTest.java +++ b/java/test/org/openqa/selenium/bidi/input/SetFilesCommandTest.java @@ -29,27 +29,23 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.bidi.module.Input; import org.openqa.selenium.bidi.script.RemoteReference; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; public class SetFilesCommandTest extends JupiterTestBase { private Input input; private String windowHandle; - private AppServer server; - @BeforeEach public void setUp() { windowHandle = driver.getWindowHandle(); input = new Input(driver); - server = new NettyAppServer(); - server.start(); } @Test + @NeedsFreshDriver void canSetFiles() throws IOException { driver.get(pages.formPage); WebElement uploadElement = driver.findElement(By.id("upload")); @@ -71,6 +67,7 @@ void canSetFiles() throws IOException { } @Test + @NeedsFreshDriver public void canSetFilesWithElementId() throws IOException { driver.get(pages.formPage); WebElement uploadElement = driver.findElement(By.id("upload")); @@ -88,6 +85,7 @@ public void canSetFilesWithElementId() throws IOException { } @Test + @NeedsFreshDriver void canSetFile() throws IOException { driver.get(pages.formPage); WebElement uploadElement = driver.findElement(By.id("upload")); @@ -106,6 +104,7 @@ void canSetFile() throws IOException { } @Test + @NeedsFreshDriver void canSetFileWithElementId() throws IOException { driver.get(pages.formPage); WebElement uploadElement = driver.findElement(By.id("upload")); diff --git a/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java b/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java index be6e7a0f12f9c..5619a890b0fc1 100644 --- a/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java +++ b/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.assertj.core.api.AssertionsForClassTypes.fail; -import static org.openqa.selenium.testing.Safely.safelyCall; import java.util.HashSet; import java.util.Set; @@ -29,36 +28,27 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.module.LogInspector; import org.openqa.selenium.bidi.script.Source; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; class LogInspectorTest extends JupiterTestBase { String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver void canListenToConsoleLog() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onConsoleEntry(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("consoleLog")).click(); @@ -76,12 +66,13 @@ void canListenToConsoleLog() throws ExecutionException, InterruptedException, Ti } @Test + @NeedsFreshDriver void canFilterConsoleLogs() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onConsoleEntry(future::complete, FilterBy.logLevel(LogLevel.INFO)); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("consoleLog")).click(); @@ -111,13 +102,14 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim } @Test + @NeedsFreshDriver void canListenToJavascriptLog() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onJavaScriptLog(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -134,12 +126,13 @@ void canListenToJavascriptLog() } @Test + @NeedsFreshDriver void canFilterJavascriptLogs() throws ExecutionException, InterruptedException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onJavaScriptLog(future::complete, FilterBy.logLevel(LogLevel.ERROR)); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -165,13 +158,14 @@ void canFilterJavascriptLogs() throws ExecutionException, InterruptedException { } @Test + @NeedsFreshDriver void canListenToJavascriptErrorLog() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onJavaScriptException(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -184,13 +178,14 @@ void canListenToJavascriptErrorLog() } @Test + @NeedsFreshDriver void canRetrieveStacktraceForALog() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onJavaScriptException(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("logWithStacktrace")).click(); @@ -202,12 +197,13 @@ void canRetrieveStacktraceForALog() } @Test + @NeedsFreshDriver void canFilterLogs() throws ExecutionException, InterruptedException { try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onLog(future::complete, FilterBy.logLevel(LogLevel.INFO)); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("consoleLog")).click(); @@ -231,9 +227,10 @@ void canFilterLogs() throws ExecutionException, InterruptedException { @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToConsoleLogForABrowsingContext() throws ExecutionException, InterruptedException, TimeoutException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String browsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); try (LogInspector logInspector = new LogInspector(browsingContextId, driver)) { @@ -255,9 +252,10 @@ void canListenToConsoleLogForABrowsingContext() @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToJavascriptLogForABrowsingContext() throws ExecutionException, InterruptedException, TimeoutException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String browsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); try (LogInspector logInspector = new LogInspector(browsingContextId, driver)) { @@ -277,9 +275,10 @@ void canListenToJavascriptLogForABrowsingContext() @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToJavascriptErrorLogForABrowsingContext() throws ExecutionException, InterruptedException, TimeoutException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String browsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); try (LogInspector logInspector = new LogInspector(browsingContextId, driver)) { @@ -299,9 +298,10 @@ void canListenToJavascriptErrorLogForABrowsingContext() @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToConsoleLogForMultipleBrowsingContexts() throws ExecutionException, InterruptedException, TimeoutException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String firstBrowsingContextId = driver.getWindowHandle(); String secondBrowsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -337,8 +337,9 @@ void canListenToConsoleLogForMultipleBrowsingContexts() @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToJavascriptLogForMultipleBrowsingContexts() throws InterruptedException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String firstBrowsingContextId = driver.getWindowHandle(); String secondBrowsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -374,8 +375,9 @@ void canListenToJavascriptLogForMultipleBrowsingContexts() throws InterruptedExc @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToJavascriptErrorLogForMultipleBrowsingContexts() throws InterruptedException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String firstBrowsingContextId = driver.getWindowHandle(); String secondBrowsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -411,8 +413,9 @@ void canListenToJavascriptErrorLogForMultipleBrowsingContexts() throws Interrupt @Disabled("Until browsers support subscribing to multiple contexts.") @Test + @NeedsFreshDriver void canListenToAnyTypeOfLogForMultipleBrowsingContexts() throws InterruptedException { - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); String firstBrowsingContextId = driver.getWindowHandle(); String secondBrowsingContextId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -440,6 +443,7 @@ void canListenToAnyTypeOfLogForMultipleBrowsingContexts() throws InterruptedExce } @Test + @NeedsFreshDriver void canListenToLogsWithMultipleConsumers() throws ExecutionException, InterruptedException, TimeoutException { try (LogInspector logInspector = new LogInspector(driver)) { @@ -449,7 +453,7 @@ void canListenToLogsWithMultipleConsumers() CompletableFuture completableFuture2 = new CompletableFuture<>(); logInspector.onJavaScriptLog(completableFuture2::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); driver.findElement(By.id("jsException")).click(); @@ -466,12 +470,4 @@ void canListenToLogsWithMultipleConsumers() assertThat(logEntry.getLevel()).isEqualTo(LogLevel.ERROR); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/network/AddInterceptParametersTest.java b/java/test/org/openqa/selenium/bidi/network/AddInterceptParametersTest.java index 21384e9aa5e7c..28ce439a3a653 100644 --- a/java/test/org/openqa/selenium/bidi/network/AddInterceptParametersTest.java +++ b/java/test/org/openqa/selenium/bidi/network/AddInterceptParametersTest.java @@ -18,30 +18,19 @@ package org.openqa.selenium.bidi.network; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.EDGE; import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.bidi.module.Network; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; class AddInterceptParametersTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddInterceptPhase() { try (Network network = new Network(driver)) { @@ -52,6 +41,7 @@ void canAddInterceptPhase() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddInterceptPhases() { try (Network network = new Network(driver)) { @@ -64,6 +54,7 @@ void canAddInterceptPhases() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddStringUrlPattern() { try (Network network = new Network(driver)) { @@ -76,6 +67,7 @@ void canAddStringUrlPattern() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddStringUrlPatterns() { try (Network network = new Network(driver)) { @@ -91,6 +83,7 @@ void canAddStringUrlPatterns() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddUrlPattern() { try (Network network = new Network(driver)) { @@ -110,6 +103,7 @@ void canAddUrlPattern() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canAddUrlPatterns() { try (Network network = new Network(driver)) { @@ -136,12 +130,4 @@ void canAddUrlPatterns() { assertThat(intercept).isNotNull(); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java b/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java index 1b82ad4d13861..cb7c065bb49ba 100644 --- a/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java +++ b/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java @@ -19,15 +19,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.*; import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openqa.selenium.Alert; @@ -36,23 +33,16 @@ import org.openqa.selenium.UsernameAndPassword; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.bidi.module.Network; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; class NetworkCommandsTest extends JupiterTestBase { private String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canAddIntercept() { @@ -64,6 +54,7 @@ void canAddIntercept() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canContinueRequest() throws InterruptedException { @@ -73,7 +64,7 @@ void canContinueRequest() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); - // String alternatePage = server.whereIs("printPage.html"); + // String alternatePage = appServer.whereIs("printPage.html"); // TODO: Test sending request to alternate page once it is supported by browsers network.onBeforeRequestSent( beforeRequestSent -> { @@ -89,7 +80,7 @@ void canContinueRequest() throws InterruptedException { assertThat(intercept).isNotNull(); - driver.get(server.whereIs("/bidi/logEntryAdded.html")); + driver.get(appServer.whereIs("/bidi/logEntryAdded.html")); boolean countdown = latch.await(5, TimeUnit.SECONDS); assertThat(countdown).isTrue(); @@ -97,6 +88,7 @@ void canContinueRequest() throws InterruptedException { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canContinueResponse() throws InterruptedException { @@ -117,7 +109,7 @@ void canContinueResponse() throws InterruptedException { assertThat(intercept).isNotNull(); - driver.get(server.whereIs("/bidi/logEntryAdded.html")); + driver.get(appServer.whereIs("/bidi/logEntryAdded.html")); boolean countdown = latch.await(5, TimeUnit.SECONDS); assertThat(countdown).isTrue(); @@ -125,6 +117,7 @@ void canContinueResponse() throws InterruptedException { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canProvideResponse() throws InterruptedException { @@ -144,7 +137,7 @@ void canProvideResponse() throws InterruptedException { assertThat(intercept).isNotNull(); - driver.get(server.whereIs("/bidi/logEntryAdded.html")); + driver.get(appServer.whereIs("/bidi/logEntryAdded.html")); boolean countdown = latch.await(5, TimeUnit.SECONDS); assertThat(countdown).isTrue(); @@ -177,7 +170,7 @@ void canProvideResponseWithAllParameters() throws InterruptedException { assertThat(intercept).isNotNull(); - driver.get(server.whereIs("/bidi/logEntryAdded.html")); + driver.get(appServer.whereIs("/bidi/logEntryAdded.html")); boolean countdown = latch.await(5, TimeUnit.SECONDS); assertThat(countdown).isTrue(); @@ -187,6 +180,7 @@ void canProvideResponseWithAllParameters() throws InterruptedException { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canRemoveIntercept() { @@ -200,6 +194,7 @@ void canRemoveIntercept() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canContinueWithAuthCredentials() { @@ -211,13 +206,14 @@ void canContinueWithAuthCredentials() { responseDetails.getRequest().getRequestId(), 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 @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canContinueWithoutAuthCredentials() { @@ -227,7 +223,7 @@ void canContinueWithoutAuthCredentials() { responseDetails -> // Does not handle the alert network.continueWithAuthNoCredentials(responseDetails.getRequest().getRequestId())); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); // This would fail if alert was handled Alert alert = wait.until(ExpectedConditions.alertIsPresent()); @@ -236,6 +232,7 @@ void canContinueWithoutAuthCredentials() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canCancelAuth() { @@ -245,7 +242,7 @@ void canCancelAuth() { responseDetails -> // Does not handle the alert network.cancelAuth(responseDetails.getRequest().getRequestId())); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); assertThatThrownBy(() -> wait.until(ExpectedConditions.alertIsPresent())) .isInstanceOf(TimeoutException.class); @@ -253,6 +250,7 @@ void canCancelAuth() { } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canFailRequest() { @@ -260,18 +258,10 @@ void canFailRequest() { network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT)); network.onBeforeRequestSent( responseDetails -> network.failRequest(responseDetails.getRequest().getRequestId())); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.manage().timeouts().pageLoadTimeout(Duration.of(5, ChronoUnit.SECONDS)); assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java b/java/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java index 28beec38ff0ab..7f221f6fc20bc 100644 --- a/java/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java +++ b/java/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java @@ -18,44 +18,34 @@ package org.openqa.selenium.bidi.network; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.bidi.module.Network; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; import org.openqa.selenium.testing.Pages; class NetworkEventsTest extends JupiterTestBase { private String page; - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canListenToBeforeRequestSentEvent() throws ExecutionException, InterruptedException, TimeoutException { try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); network.onBeforeRequestSent(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); BeforeRequestSent requestSent = future.get(5, TimeUnit.SECONDS); @@ -69,13 +59,14 @@ void canListenToBeforeRequestSentEvent() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canListenToResponseStartedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); network.onResponseStarted(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); ResponseDetails response = future.get(5, TimeUnit.SECONDS); @@ -91,13 +82,14 @@ void canListenToResponseStartedEvent() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canListenToResponseCompletedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); network.onResponseCompleted(future::complete); - page = server.whereIs("/bidi/logEntryAdded.html"); + page = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(page); ResponseDetails response = future.get(5, TimeUnit.SECONDS); @@ -113,13 +105,14 @@ void canListenToResponseCompletedEvent() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) void canListenToResponseCompletedEventWithCookie() throws ExecutionException, InterruptedException, TimeoutException { try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); - driver.get(new Pages(server).blankPage); + driver.get(new Pages(appServer).blankPage); driver.manage().addCookie(new Cookie("foo", "bar")); network.onBeforeRequestSent(future::complete); driver.navigate().refresh(); @@ -135,6 +128,7 @@ void canListenToResponseCompletedEventWithCookie() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canListenToOnAuthRequiredEvent() @@ -142,7 +136,7 @@ void canListenToOnAuthRequiredEvent() try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); network.onAuthRequired(future::complete); - page = server.whereIs("basicAuth"); + page = appServer.whereIs("basicAuth"); driver.get(page); ResponseDetails response = future.get(5, TimeUnit.SECONDS); @@ -158,13 +152,14 @@ void canListenToOnAuthRequiredEvent() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) void canListenToFetchError() throws ExecutionException, InterruptedException, TimeoutException { try (Network network = new Network(driver)) { CompletableFuture future = new CompletableFuture<>(); network.onFetchError(future::complete); - page = server.whereIs("error"); + page = appServer.whereIs("error"); try { driver.get("https://not_a_valid_url.test/"); } catch (WebDriverException ignored) { @@ -181,12 +176,4 @@ void canListenToFetchError() throws ExecutionException, InterruptedException, Ti assertThat(fetchError.getErrorText()).contains("UNKNOWN_HOST"); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/script/CallFunctionParameterTest.java b/java/test/org/openqa/selenium/bidi/script/CallFunctionParameterTest.java index 7caeb5fa8aad7..e853e39296431 100644 --- a/java/test/org/openqa/selenium/bidi/script/CallFunctionParameterTest.java +++ b/java/test/org/openqa/selenium/bidi/script/CallFunctionParameterTest.java @@ -18,7 +18,6 @@ package org.openqa.selenium.bidi.script; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.IE; import static org.openqa.selenium.testing.drivers.Browser.SAFARI; @@ -26,27 +25,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.module.Script; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; public class CallFunctionParameterTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } - @Test + @NeedsFreshDriver void canCallFunctionWithDeclaration() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -65,6 +54,7 @@ void canCallFunctionWithDeclaration() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithUserActivationTrue() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -93,6 +83,7 @@ void canEvaluateScriptWithUserActivationTrue() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithUserActivationFalse() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -121,6 +112,7 @@ void canEvaluateScriptWithUserActivationFalse() { } @Test + @NeedsFreshDriver void canCallFunctionWithArguments() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -147,6 +139,7 @@ void canCallFunctionWithArguments() { } @Test + @NeedsFreshDriver void canCallFunctionToGetIFrameBrowsingContext() { String url = appServer.whereIs("click_too_big_in_frame.html"); driver.get(url); @@ -180,6 +173,7 @@ void canCallFunctionToGetIFrameBrowsingContext() { } @Test + @NeedsFreshDriver void canCallFunctionToGetElement() { String url = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(url); @@ -207,6 +201,7 @@ void canCallFunctionToGetElement() { } @Test + @NeedsFreshDriver void canCallFunctionWithAwaitPromise() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -233,6 +228,7 @@ void canCallFunctionWithAwaitPromise() { } @Test + @NeedsFreshDriver void canCallFunctionWithAwaitPromiseFalse() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -257,6 +253,7 @@ void canCallFunctionWithAwaitPromiseFalse() { } @Test + @NeedsFreshDriver void canCallFunctionWithThisParameter() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -282,6 +279,7 @@ void canCallFunctionWithThisParameter() { } @Test + @NeedsFreshDriver void canCallFunctionWithOwnershipRoot() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -301,6 +299,7 @@ void canCallFunctionWithOwnershipRoot() { } @Test + @NeedsFreshDriver void canCallFunctionWithOwnershipNone() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -320,6 +319,7 @@ void canCallFunctionWithOwnershipNone() { } @Test + @NeedsFreshDriver @NotYetImplemented(SAFARI) @NotYetImplemented(IE) void canCallFunctionThatThrowsException() { @@ -346,6 +346,7 @@ void canCallFunctionThatThrowsException() { } @Test + @NeedsFreshDriver void canCallFunctionInASandBox() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -386,6 +387,7 @@ void canCallFunctionInASandBox() { } @Test + @NeedsFreshDriver void canCallFunctionInARealm() { String firstTab = driver.getWindowHandle(); String secondTab = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -430,12 +432,4 @@ void canCallFunctionInARealm() { assertThat((Long) successSecondContextresult.getResult().getValue().get()).isEqualTo(5L); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/script/EvaluateParametersTest.java b/java/test/org/openqa/selenium/bidi/script/EvaluateParametersTest.java index 7a3087d1136f2..e51dff72265fb 100644 --- a/java/test/org/openqa/selenium/bidi/script/EvaluateParametersTest.java +++ b/java/test/org/openqa/selenium/bidi/script/EvaluateParametersTest.java @@ -18,29 +18,19 @@ package org.openqa.selenium.bidi.script; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WindowType; import org.openqa.selenium.bidi.module.Script; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; public class EvaluateParametersTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver void canEvaluateScript() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -58,6 +48,7 @@ void canEvaluateScript() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithUserActivationTrue() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -85,6 +76,7 @@ void canEvaluateScriptWithUserActivationTrue() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithUserActivationFalse() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -112,6 +104,7 @@ void canEvaluateScriptWithUserActivationFalse() { } @Test + @NeedsFreshDriver void canEvaluateScriptThatThrowsException() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -133,6 +126,7 @@ void canEvaluateScriptThatThrowsException() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithResulWithOwnership() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -152,6 +146,7 @@ void canEvaluateScriptWithResulWithOwnership() { } @Test + @NeedsFreshDriver void canEvaluateInASandBox() { String id = driver.getWindowHandle(); try (Script script = new Script(id, driver)) { @@ -191,6 +186,7 @@ void canEvaluateInASandBox() { } @Test + @NeedsFreshDriver void canEvaluateInARealm() { String firstTab = driver.getWindowHandle(); String secondTab = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -229,12 +225,4 @@ void canEvaluateInARealm() { assertThat((Long) successSecondContextResult.getResult().getValue().get()).isEqualTo(5L); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java b/java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java index 108e2d1554513..059ca1bb43814 100644 --- a/java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java +++ b/java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import java.util.ArrayList; import java.util.HashMap; @@ -31,8 +30,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriverException; @@ -41,21 +38,14 @@ import org.openqa.selenium.bidi.log.LogLevel; import org.openqa.selenium.bidi.module.LogInspector; import org.openqa.selenium.bidi.module.Script; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.Pages; public class ScriptCommandsTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver void canCallFunctionWithDeclaration() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -74,6 +64,7 @@ void canCallFunctionWithDeclaration() { } @Test + @NeedsFreshDriver void canCallFunctionWithArguments() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -103,6 +94,7 @@ void canCallFunctionWithArguments() { } @Test + @NeedsFreshDriver void canCallFunctionToGetIFrameBrowsingContext() { String url = appServer.whereIs("click_too_big_in_frame.html"); driver.get(url); @@ -136,6 +128,7 @@ void canCallFunctionToGetIFrameBrowsingContext() { } @Test + @NeedsFreshDriver void canCallFunctionToGetElement() { String url = appServer.whereIs("/bidi/logEntryAdded.html"); driver.get(url); @@ -165,6 +158,7 @@ void canCallFunctionToGetElement() { } @Test + @NeedsFreshDriver void canCallFunctionWithAwaitPromise() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -192,6 +186,7 @@ void canCallFunctionWithAwaitPromise() { } @Test + @NeedsFreshDriver void canCallFunctionWithAwaitPromiseFalse() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -217,6 +212,7 @@ void canCallFunctionWithAwaitPromiseFalse() { } @Test + @NeedsFreshDriver void canCallFunctionWithThisParameter() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -244,6 +240,7 @@ void canCallFunctionWithThisParameter() { } @Test + @NeedsFreshDriver void canCallFunctionWithOwnershipRoot() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -266,6 +263,7 @@ void canCallFunctionWithOwnershipRoot() { } @Test + @NeedsFreshDriver void canCallFunctionWithOwnershipNone() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -288,6 +286,7 @@ void canCallFunctionWithOwnershipNone() { } @Test + @NeedsFreshDriver void canCallFunctionThatThrowsException() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -313,6 +312,7 @@ void canCallFunctionThatThrowsException() { } @Test + @NeedsFreshDriver void canCallFunctionInASandBox() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -373,6 +373,7 @@ void canCallFunctionInASandBox() { } @Test + @NeedsFreshDriver void canCallFunctionInARealm() { String firstTab = driver.getWindowHandle(); String secondTab = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -433,6 +434,7 @@ void canCallFunctionInARealm() { } @Test + @NeedsFreshDriver void canEvaluateScript() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -450,6 +452,7 @@ void canEvaluateScript() { } @Test + @NeedsFreshDriver void canEvaluateScriptThatThrowsException() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -469,6 +472,7 @@ void canEvaluateScriptThatThrowsException() { } @Test + @NeedsFreshDriver void canEvaluateScriptWithResulWithOwnership() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -487,6 +491,7 @@ void canEvaluateScriptWithResulWithOwnership() { } @Test + @NeedsFreshDriver void canEvaluateInASandBox() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -523,6 +528,7 @@ void canEvaluateInASandBox() { } @Test + @NeedsFreshDriver void canEvaluateInARealm() { String firstTab = driver.getWindowHandle(); String secondTab = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -559,6 +565,7 @@ void canEvaluateInARealm() { } @Test + @NeedsFreshDriver void canDisownHandles() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -615,6 +622,7 @@ void canDisownHandles() { } @Test + @NeedsFreshDriver void canDisownHandlesInRealm() { String id = driver.getWindowHandle(); Script script = new Script(id, driver); @@ -671,6 +679,7 @@ void canDisownHandlesInRealm() { } @Test + @NeedsFreshDriver void canGetAllRealms() { String firstWindow = driver.getWindowHandle(); String secondWindow = driver.switchTo().newWindow(WindowType.WINDOW).getWindowHandle(); @@ -695,6 +704,7 @@ void canGetAllRealms() { } @Test + @NeedsFreshDriver void canGetRealmByType() { String firstWindow = driver.getWindowHandle(); String secondWindow = driver.switchTo().newWindow(WindowType.WINDOW).getWindowHandle(); @@ -719,6 +729,7 @@ void canGetRealmByType() { } @Test + @NeedsFreshDriver void canGetRealmInBrowsingContext() { String windowId = driver.getWindowHandle(); String tabId = driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -735,6 +746,7 @@ void canGetRealmInBrowsingContext() { } @Test + @NeedsFreshDriver void canGetRealmInBrowsingContextByType() { String windowId = driver.getWindowHandle(); driver.switchTo().newWindow(WindowType.TAB).getWindowHandle(); @@ -752,6 +764,7 @@ void canGetRealmInBrowsingContextByType() { } @Test + @NeedsFreshDriver void canAddPreloadScript() throws ExecutionException, InterruptedException, TimeoutException { Script script = new Script(driver); String id = script.addPreloadScript("() => {{ console.log('{preload_script_console_text}') }}"); @@ -763,7 +776,7 @@ void canAddPreloadScript() throws ExecutionException, InterruptedException, Time CompletableFuture future = new CompletableFuture<>(); logInspector.onConsoleEntry(future::complete); - driver.get(new Pages(server).blankPage); + driver.get(new Pages(appServer).blankPage); ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS); @@ -774,6 +787,7 @@ void canAddPreloadScript() throws ExecutionException, InterruptedException, Time } @Test + @NeedsFreshDriver void canAddPreloadScriptWithArguments() { Script script = new Script(driver); String id = @@ -785,6 +799,7 @@ void canAddPreloadScriptWithArguments() { } @Test + @NeedsFreshDriver void canAddPreloadScriptWithChannelOptions() { Script script = new Script(driver); SerializationOptions serializationOptions = new SerializationOptions(); @@ -798,13 +813,14 @@ void canAddPreloadScriptWithChannelOptions() { } @Test + @NeedsFreshDriver void canAddPreloadScriptInASandbox() { Script script = new Script(driver); String id = script.addPreloadScript("() => { window.bar=2; }", "sandbox"); assertThat(id).isNotNull(); assertThat(id).isNotEmpty(); - driver.get(new Pages(server).blankPage); + driver.get(new Pages(appServer).blankPage); EvaluateResult result = script.evaluateFunctionInBrowsingContext( @@ -814,13 +830,14 @@ void canAddPreloadScriptInASandbox() { } @Test + @NeedsFreshDriver void canRemovePreloadedScript() { Script script = new Script(driver.getWindowHandle(), driver); String id = script.addPreloadScript("() => { window.bar=2; }"); assertThat(id).isNotNull(); assertThat(id).isNotEmpty(); - driver.get(new Pages(server).blankPage); + driver.get(new Pages(appServer).blankPage); EvaluateResult result = script.evaluateFunctionInBrowsingContext( @@ -837,12 +854,4 @@ void canRemovePreloadedScript() { assertThat(((EvaluateResultSuccess) resultAfterRemoval).getResult().getValue().isPresent()) .isFalse(); } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java b/java/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java index 6696794291447..8893ff050ab10 100644 --- a/java/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java +++ b/java/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java @@ -17,7 +17,6 @@ package org.openqa.selenium.bidi.script; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.openqa.selenium.testing.Safely.safelyCall; import static org.openqa.selenium.testing.drivers.Browser.*; import java.util.List; @@ -26,27 +25,18 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.bidi.browsingcontext.BrowsingContext; import org.openqa.selenium.bidi.module.Script; -import org.openqa.selenium.environment.webserver.AppServer; -import org.openqa.selenium.environment.webserver.NettyAppServer; import org.openqa.selenium.testing.JupiterTestBase; +import org.openqa.selenium.testing.NeedsFreshDriver; import org.openqa.selenium.testing.NotYetImplemented; import org.openqa.selenium.testing.Pages; public class ScriptEventsTest extends JupiterTestBase { - private AppServer server; - - @BeforeEach - public void setUp() { - server = new NettyAppServer(); - server.start(); - } @Test + @NeedsFreshDriver void canListenToChannelMessage() throws ExecutionException, InterruptedException, TimeoutException { try (Script script = new Script(driver)) { @@ -74,6 +64,7 @@ void canListenToChannelMessage() } @Test + @NeedsFreshDriver void canListenToRealmCreatedEvent() throws ExecutionException, InterruptedException, TimeoutException { try (Script script = new Script(driver)) { @@ -82,7 +73,7 @@ void canListenToRealmCreatedEvent() BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); - context.navigate(new Pages(server).blankPage); + context.navigate(new Pages(appServer).blankPage); RealmInfo realmInfo = future.get(5, TimeUnit.SECONDS); assertThat(realmInfo.getRealmId()).isNotNull(); assertThat(realmInfo.getRealmType()).isEqualTo(RealmType.WINDOW); @@ -90,6 +81,7 @@ void canListenToRealmCreatedEvent() } @Test + @NeedsFreshDriver @NotYetImplemented(EDGE) @NotYetImplemented(CHROME) @NotYetImplemented(FIREFOX) @@ -107,12 +99,4 @@ void canListenToRealmDestroyedEvent() assertThat(realmInfo.getRealmType()).isEqualTo(RealmType.WINDOW); } } - - @AfterEach - public void quitDriver() { - if (driver != null) { - driver.quit(); - } - safelyCall(server::stop); - } } diff --git a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java index aee7a084a388b..a9debd364b8f1 100644 --- a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java +++ b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java @@ -27,7 +27,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; @@ -54,8 +56,14 @@ import org.openqa.selenium.testing.drivers.Browser; class RemoteWebDriverBiDiTest { + private static AppServer server; private WebDriver driver; - private AppServer server; + + @BeforeAll + static void serverSetup() { + server = new NettyAppServer(); + server.start(); + } @BeforeEach void setup() { @@ -73,9 +81,6 @@ void setup() { driver = new RemoteWebDriver(deployment.getServer().getUrl(), browser.getCapabilities()); driver = new Augmenter().augment(driver); - - server = new NettyAppServer(); - server.start(); } @Test @@ -138,6 +143,10 @@ void canNavigateToUrl() { @AfterEach void clean() { driver.quit(); + } + + @AfterAll + static void stopServer() { server.stop(); } }