Class NetworkInterceptor

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class NetworkInterceptor
    extends java.lang.Object
    implements java.io.Closeable
    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. }

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.openqa.selenium.remote.http.HttpResponse PROCEED_WITH_REQUEST  
    • Constructor Summary

      Constructors 
      Constructor Description
      NetworkInterceptor​(org.openqa.selenium.WebDriver driver, org.openqa.selenium.remote.http.Route route)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROCEED_WITH_REQUEST

        public static final org.openqa.selenium.remote.http.HttpResponse PROCEED_WITH_REQUEST
    • Constructor Detail

      • NetworkInterceptor

        public NetworkInterceptor​(org.openqa.selenium.WebDriver driver,
                                  org.openqa.selenium.remote.http.Route route)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable