From 38829c7c637f9defb2e76f4b6747d6c3065cc4e9 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Fri, 5 Apr 2024 16:18:53 +0530 Subject: [PATCH] [bidi][java] Enable grid BiDi chrome test (#13778) --- .../openqa/selenium/grid/router/BUILD.bazel | 13 +-- .../grid/router/RemoteWebDriverBiDiTest.java | 88 +++++++------------ 2 files changed, 40 insertions(+), 61 deletions(-) diff --git a/java/test/org/openqa/selenium/grid/router/BUILD.bazel b/java/test/org/openqa/selenium/grid/router/BUILD.bazel index 9766de9de45ff..af5d143374150 100644 --- a/java/test/org/openqa/selenium/grid/router/BUILD.bazel +++ b/java/test/org/openqa/selenium/grid/router/BUILD.bazel @@ -10,7 +10,7 @@ LARGE_TESTS = [ "StressTest.java", ] -FIREFOX_ONLY_LARGE_TESTS = [ +FIREFOX_CHROME_ONLY_LARGE_TESTS = [ "RemoteWebDriverBiDiTest.java", ] @@ -77,10 +77,13 @@ java_selenium_test_suite( ) java_selenium_test_suite( - name = "firefox-only-large-tests", + name = "firefox-chrome-only-large-tests", size = "large", - srcs = FIREFOX_ONLY_LARGE_TESTS, - browsers = ["firefox"], + srcs = FIREFOX_CHROME_ONLY_LARGE_TESTS, + browsers = [ + "firefox", + "chrome", + ], deps = [ ":support", "//java/src/org/openqa/selenium/bidi", @@ -103,7 +106,7 @@ java_test_suite( size = "medium", srcs = glob( ["*Test.java"], - exclude = LARGE_TESTS + FIREFOX_ONLY_LARGE_TESTS, + exclude = LARGE_TESTS + FIREFOX_CHROME_ONLY_LARGE_TESTS, ), tags = [ "requires-network", diff --git a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java index a9544b0723313..68c6486f64a71 100644 --- a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java +++ b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java @@ -18,13 +18,17 @@ package org.openqa.selenium.grid.router; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.openqa.selenium.testing.drivers.Browser.*; import java.io.StringReader; import java.util.Collections; +import java.util.Objects; 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.WebDriver; @@ -40,18 +44,21 @@ 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.firefox.FirefoxOptions; import org.openqa.selenium.grid.config.TomlConfig; import org.openqa.selenium.grid.router.DeploymentTypes.Deployment; import org.openqa.selenium.remote.Augmenter; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.testing.Ignore; +import org.openqa.selenium.testing.NotYetImplemented; import org.openqa.selenium.testing.drivers.Browser; class RemoteWebDriverBiDiTest { + private WebDriver driver; + private AppServer server; - @Test - void ensureBiDiSessionCreation() { - Browser browser = Browser.FIREFOX; + @BeforeEach + void setup() { + Browser browser = Objects.requireNonNull(Browser.detect()); Deployment deployment = DeploymentTypes.STANDALONE.start( @@ -63,47 +70,34 @@ void ensureBiDiSessionCreation() { + "driver-implementation = " + browser.displayName()))); - FirefoxOptions options = createFirefoxOptions(); - // Enable BiDi - options.setCapability("webSocketUrl", true); - options.merge(Browser.FIREFOX.getCapabilities()); - - WebDriver driver = new RemoteWebDriver(deployment.getServer().getUrl(), options); + driver = new RemoteWebDriver(deployment.getServer().getUrl(), browser.getCapabilities()); driver = new Augmenter().augment(driver); + server = new NettyAppServer(); + server.start(); + } + + @Test + @Ignore(IE) + @Ignore(SAFARI) + @NotYetImplemented(EDGE) + void ensureBiDiSessionCreation() { try (BiDi biDi = ((HasBiDi) driver).getBiDi()) { BiDiSessionStatus status = biDi.send( new Command<>("session.status", Collections.emptyMap(), BiDiSessionStatus.class)); assertThat(status).isNotNull(); - assertThat(status.getMessage()).isEqualTo("Session already started"); + assertThat(status.getMessage()).isNotEmpty(); } } @Test + @Ignore(IE) + @Ignore(SAFARI) + @NotYetImplemented(EDGE) void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutException { - Browser browser = Browser.FIREFOX; - - Deployment deployment = - DeploymentTypes.STANDALONE.start( - browser.getCapabilities(), - new TomlConfig( - new StringReader( - "[node]\n" - + "selenium-manager = false\n" - + "driver-implementation = " - + browser.displayName()))); - - FirefoxOptions options = createFirefoxOptions(); - // Enable BiDi - options.setCapability("webSocketUrl", true); - - WebDriver driver = new RemoteWebDriver(deployment.getServer().getUrl(), options); driver = new Augmenter().augment(driver); - AppServer server = new NettyAppServer(); - server.start(); - try (LogInspector logInspector = new LogInspector(driver)) { CompletableFuture future = new CompletableFuture<>(); logInspector.onConsoleEntry(future::complete); @@ -120,34 +114,14 @@ void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutE assertThat(logEntry.getType()).isEqualTo("console"); assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO); assertThat(logEntry.getMethod()).isEqualTo("log"); - assertThat(logEntry.getStackTrace()).isNull(); } } @Test + @Ignore(IE) + @Ignore(SAFARI) + @NotYetImplemented(EDGE) void canNavigateToUrl() { - Browser browser = Browser.FIREFOX; - - Deployment deployment = - DeploymentTypes.STANDALONE.start( - browser.getCapabilities(), - new TomlConfig( - new StringReader( - "[node]\n" - + "selenium-manager = false\n" - + "driver-implementation = " - + browser.displayName()))); - - FirefoxOptions options = createFirefoxOptions(); - // Enable BiDi - options.setCapability("webSocketUrl", true); - - WebDriver driver = new RemoteWebDriver(deployment.getServer().getUrl(), options); - driver = new Augmenter().augment(driver); - - AppServer server = new NettyAppServer(); - server.start(); - BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB); String url = server.whereIs("/bidi/logEntryAdded.html"); @@ -158,7 +132,9 @@ void canNavigateToUrl() { assertThat(info.getUrl()).contains("/bidi/logEntryAdded.html"); } - private FirefoxOptions createFirefoxOptions() { - return (FirefoxOptions) Browser.FIREFOX.getCapabilities(); + @AfterEach + void clean() { + driver.quit(); + server.stop(); } }