Skip to content

Commit

Permalink
[bidi][java] Enable chrome tests for Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Apr 4, 2024
1 parent f1032eb commit 44f636d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 82 deletions.
31 changes: 5 additions & 26 deletions java/test/org/openqa/selenium/grid/router/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ LARGE_TESTS = [
"NewSessionCreationTest.java",
"RemoteWebDriverDownloadTest.java",
"StressTest.java",
]

FIREFOX_ONLY_LARGE_TESTS = [
"RemoteWebDriverBiDiTest.java",
]

Expand Down Expand Up @@ -56,6 +53,10 @@ java_selenium_test_suite(
],
deps = [
":support",
"//java/src/org/openqa/selenium/bidi",
"//java/src/org/openqa/selenium/bidi/browsingcontext",
"//java/src/org/openqa/selenium/bidi/log",
"//java/src/org/openqa/selenium/bidi/module",
"//java/src/org/openqa/selenium/chrome",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/grid",
Expand All @@ -76,34 +77,12 @@ java_selenium_test_suite(
] + CDP_DEPS + JUNIT5_DEPS,
)

java_selenium_test_suite(
name = "firefox-only-large-tests",
size = "large",
srcs = FIREFOX_ONLY_LARGE_TESTS,
browsers = ["firefox"],
deps = [
":support",
"//java/src/org/openqa/selenium/bidi",
"//java/src/org/openqa/selenium/bidi/browsingcontext",
"//java/src/org/openqa/selenium/bidi/log",
"//java/src/org/openqa/selenium/bidi/module",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/grid/config",
"//java/src/org/openqa/selenium/remote",
"//java/test/org/openqa/selenium/environment",
"//java/test/org/openqa/selenium/testing:annotations",
"//java/test/org/openqa/selenium/testing:test-base",
artifact("org.junit.jupiter:junit-jupiter-api"),
artifact("org.assertj:assertj-core"),
] + CDP_DEPS + JUNIT5_DEPS,
)

java_test_suite(
name = "medium-tests",
size = "medium",
srcs = glob(
["*Test.java"],
exclude = LARGE_TESTS + FIREFOX_ONLY_LARGE_TESTS,
exclude = LARGE_TESTS,
),
tags = [
"requires-network",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,18 +44,20 @@
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.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(
Expand All @@ -63,47 +69,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)
@Ignore(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)
@Ignore(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<ConsoleLogEntry> future = new CompletableFuture<>();
logInspector.onConsoleEntry(future::complete);
Expand All @@ -120,34 +113,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)
@Ignore(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");
Expand All @@ -158,7 +131,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();
}
}

0 comments on commit 44f636d

Please sign in to comment.