Skip to content

Commit 6ad24d3

Browse files
committed
[bidi][java] Add failRequest command
1 parent a9a0aa4 commit 6ad24d3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

java/src/org/openqa/selenium/bidi/Network.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public void cancelAuth(String requestId) {
110110
"network.continueWithAuth", Map.of("request", requestId, "action", "cancel")));
111111
}
112112

113+
public void failRequest(String requestId) {
114+
this.bidi.send(new Command<>("network.failRequest", Map.of("request", requestId)));
115+
}
116+
113117
public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer) {
114118
if (browsingContextIds.isEmpty()) {
115119
this.bidi.addListener(beforeRequestSentEvent, consumer);

java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import static org.openqa.selenium.testing.drivers.Browser.IE;
2626
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
2727

28+
import java.time.Duration;
29+
import java.time.temporal.ChronoUnit;
2830
import org.junit.jupiter.api.AfterEach;
2931
import org.junit.jupiter.api.BeforeEach;
3032
import org.junit.jupiter.api.Test;
3133
import org.openqa.selenium.Alert;
3234
import org.openqa.selenium.By;
3335
import org.openqa.selenium.TimeoutException;
3436
import org.openqa.selenium.UsernameAndPassword;
37+
import org.openqa.selenium.WebDriverException;
3538
import org.openqa.selenium.bidi.Network;
3639
import org.openqa.selenium.environment.webserver.AppServer;
3740
import org.openqa.selenium.environment.webserver.NettyAppServer;
@@ -136,6 +139,23 @@ void canCancelAuth() {
136139
}
137140
}
138141

142+
@Test
143+
@NotYetImplemented(SAFARI)
144+
@NotYetImplemented(IE)
145+
@NotYetImplemented(EDGE)
146+
@NotYetImplemented(FIREFOX)
147+
void canFailRequest() {
148+
try (Network network = new Network(driver)) {
149+
network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
150+
network.onBeforeRequestSent(
151+
responseDetails -> network.failRequest(responseDetails.getRequest().getRequestId()));
152+
page = server.whereIs("basicAuth");
153+
driver.manage().timeouts().pageLoadTimeout(Duration.of(5, ChronoUnit.SECONDS));
154+
155+
assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class);
156+
}
157+
}
158+
139159
@AfterEach
140160
public void quitDriver() {
141161
if (driver != null) {

0 commit comments

Comments
 (0)