Skip to content

Commit

Permalink
Merge 9ba73d5 into 111941b
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Apr 5, 2024
2 parents 111941b + 9ba73d5 commit 3148e63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 61 deletions.
13 changes: 8 additions & 5 deletions java/test/org/openqa/selenium/grid/router/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LARGE_TESTS = [
"StressTest.java",
]

FIREFOX_ONLY_LARGE_TESTS = [
FIREFOX_CHROME_ONLY_LARGE_TESTS = [
"RemoteWebDriverBiDiTest.java",
]

Expand Down Expand Up @@ -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",
Expand All @@ -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",
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,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(
Expand All @@ -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<ConsoleLogEntry> future = new CompletableFuture<>();
logInspector.onConsoleEntry(future::complete);
Expand All @@ -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");
Expand All @@ -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();
}
}

0 comments on commit 3148e63

Please sign in to comment.