From 6ad24d37316c98f2f8c3fde9d66864c94400e676 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Thu, 25 Jan 2024 18:25:22 +0530 Subject: [PATCH] [bidi][java] Add failRequest command --- .../src/org/openqa/selenium/bidi/Network.java | 4 ++++ .../bidi/network/NetworkCommandsTest.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/java/src/org/openqa/selenium/bidi/Network.java b/java/src/org/openqa/selenium/bidi/Network.java index ddbe26c7faf06..6bd26205068be 100644 --- a/java/src/org/openqa/selenium/bidi/Network.java +++ b/java/src/org/openqa/selenium/bidi/Network.java @@ -110,6 +110,10 @@ public void cancelAuth(String requestId) { "network.continueWithAuth", Map.of("request", requestId, "action", "cancel"))); } + public void failRequest(String requestId) { + this.bidi.send(new Command<>("network.failRequest", Map.of("request", requestId))); + } + public void onBeforeRequestSent(Consumer consumer) { if (browsingContextIds.isEmpty()) { this.bidi.addListener(beforeRequestSentEvent, consumer); diff --git a/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java b/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java index ad54f3a4a3f2c..681b2b1c4fd79 100644 --- a/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java +++ b/java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java @@ -25,6 +25,8 @@ import static org.openqa.selenium.testing.drivers.Browser.IE; import static org.openqa.selenium.testing.drivers.Browser.SAFARI; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,6 +34,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.UsernameAndPassword; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.bidi.Network; import org.openqa.selenium.environment.webserver.AppServer; import org.openqa.selenium.environment.webserver.NettyAppServer; @@ -136,6 +139,23 @@ void canCancelAuth() { } } + @Test + @NotYetImplemented(SAFARI) + @NotYetImplemented(IE) + @NotYetImplemented(EDGE) + @NotYetImplemented(FIREFOX) + void canFailRequest() { + try (Network network = new Network(driver)) { + network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT)); + network.onBeforeRequestSent( + responseDetails -> network.failRequest(responseDetails.getRequest().getRequestId())); + page = server.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) {