Class NetworkInterceptor

java.lang.Object
org.openqa.selenium.devtools.NetworkInterceptor
All Implemented Interfaces:
AutoCloseable

public class NetworkInterceptor extends Object implements 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).