Network
Page being translated from English to Portuguese. Do you speak Portuguese? Help us to translate it by sending us pull requests!
Commands
This section contains the APIs related to network commands.
Add network intercept
try (Network network = new Network(driver)) {
String intercept =
network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
Remove network intercept
try (Network network = new Network(driver)) {
String intercept =
network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
Assertions.assertNotNull(intercept);
network.removeIntercept(intercept);
const network = await Network(driver)
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
Continue request blocked at authRequired phase with credentials
try (Network network = new Network(driver)) {
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
network.onAuthRequired(
responseDetails ->
network.continueWithAuth(
responseDetails.getRequest().getRequestId(),
new UsernameAndPassword("admin", "admin")));
driver.get("https://the-internet.herokuapp.com/basic_auth");
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.continueWithAuth(event.request.request, 'admin','admin')
})
Continue request blocked at authRequired phase without credentials
try (Network network = new Network(driver)) {
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
network.onAuthRequired(
responseDetails ->
// Does not handle the alert
network.continueWithAuthNoCredentials(responseDetails.getRequest().getRequestId()));
driver.get("https://the-internet.herokuapp.com/basic_auth");
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.continueWithAuthNoCredentials(event.request.request)
})
Cancel request blocked at authRequired phase
try (Network network = new Network(driver)) {
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
network.onAuthRequired(
responseDetails ->
// Does not handle the alert
network.cancelAuth(responseDetails.getRequest().getRequestId()));
driver.get("https://the-internet.herokuapp.com/basic_auth");
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.cancelAuth(event.request.request)
})
Fail request
try (Network network = new Network(driver)) {
network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
network.onBeforeRequestSent(
responseDetails -> network.failRequest(responseDetails.getRequest().getRequestId()));
driver.manage().timeouts().pageLoadTimeout(Duration.of(5, ChronoUnit.SECONDS));
Events
This section contains the APIs related to network events.
Before Request Sent
try (Network network = new Network(driver)) {
CompletableFuture<BeforeRequestSent> future = new CompletableFuture<>();
network.onBeforeRequestSent(future::complete);
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
BeforeRequestSent requestSent = future.get(5, TimeUnit.SECONDS);
let beforeRequestEvent = null
const network = await Network(driver)
await network.beforeRequestSent(function (event) {
beforeRequestEvent = event
})
await driver.get('https://www.selenium.dev/selenium/web/blank.html')
Response Started
try (Network network = new Network(driver)) {
CompletableFuture<ResponseDetails> future = new CompletableFuture<>();
network.onResponseStarted(future::complete);
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
ResponseDetails response = future.get(5, TimeUnit.SECONDS);
String windowHandle = driver.getWindowHandle();
let onResponseStarted = []
const network = await Network(driver)
await network.responseStarted(function (event) {
onResponseStarted.push(event)
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
Response Completed
try (Network network = new Network(driver)) {
CompletableFuture<ResponseDetails> future = new CompletableFuture<>();
network.onResponseCompleted(future::complete);
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
ResponseDetails response = future.get(5, TimeUnit.SECONDS);
String windowHandle = driver.getWindowHandle();
let onResponseCompleted = []
const network = await Network(driver)
await network.responseCompleted(function (event) {
onResponseCompleted.push(event)
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
Auth Required
try (Network network = new Network(driver)) {
CompletableFuture<ResponseDetails> future = new CompletableFuture<>();
network.onAuthRequired(future::complete);
driver.get("https://the-internet.herokuapp.com/basic_auth");
ResponseDetails response = future.get(5, TimeUnit.SECONDS);