Package org.openqa.selenium.devtools
Class NetworkInterceptor
java.lang.Object
org.openqa.selenium.devtools.NetworkInterceptor
- All Implemented Interfaces:
AutoCloseable
Provides a mechanism for stubbing out responses to requests in drivers which implement
HasDevTools
. Usage is done by specifying a Route
, which will be checked for every
request to see if that request should be handled or not. Note that the URLs given to the
Route
will be fully qualified.
Example usage:
Route route = Route.matching(req -> GET == req.getMethod() && req.getUri().endsWith("/example"))
.to(() -> req -> new HttpResponse().setContent(Contents.utf8String("Hello, World!")));
try (NetworkInterceptor interceptor = new NetworkInterceptor(driver, route)) {
// Your code here.
}
It is also possible to intercept and modify responses that the browser will receive. Do this
by calling NetworkInterceptor(WebDriver, Filter)
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HttpResponse
Return this from aRoutable
in order to have the browser continue the request unmodified. -
Constructor Summary
ConstructorsConstructorDescriptionNetworkInterceptor
(WebDriver driver, Filter filter) NetworkInterceptor
(WebDriver driver, HttpHandler handler) NetworkInterceptor
(WebDriver driver, Routable routable) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected HttpMethod
convertFromCdpHttpMethod
(String method) protected HttpRequest
createHttpRequest
(String cdpMethod, String url, Map<String, Object> headers, Optional<String> postData)
-
Field Details
-
PROCEED_WITH_REQUEST
Return this from aRoutable
in order to have the browser continue the request unmodified.
-
-
Constructor Details
-
NetworkInterceptor
-
NetworkInterceptor
-
NetworkInterceptor
-
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
convertFromCdpHttpMethod
-
createHttpRequest
-