Skip to content

Commit

Permalink
[bidi][java] Add failRequest command
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jan 25, 2024
1 parent a9a0aa4 commit 6ad24d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java/src/org/openqa/selenium/bidi/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BeforeRequestSent> consumer) {
if (browsingContextIds.isEmpty()) {
this.bidi.addListener(beforeRequestSentEvent, consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
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;
import org.openqa.selenium.Alert;
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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6ad24d3

Please sign in to comment.