Class MockResponseFilter

java.lang.Object
com.codeborne.selenide.proxy.MockResponseFilter
All Implemented Interfaces:
com.browserup.bup.filters.RequestFilter

public class MockResponseFilter extends Object implements com.browserup.bup.filters.RequestFilter
Selenide proxy filter allowing to mock any response
  • Constructor Details

    • MockResponseFilter

      public MockResponseFilter()
  • Method Details

    • mockText

      public void mockText(String name, RequestMatcher requestMatcher, Supplier<String> mockedResponse)
    • mockText

      public void mockText(String name, RequestMatcher requestMatcher, int status, Supplier<String> mockedResponse)
    • mockBytes

      public void mockBytes(String name, RequestMatcher requestMatcher, Supplier<byte[]> mockedResponse)
    • mockBytes

      public void mockBytes(String name, RequestMatcher requestMatcher, int status, Supplier<byte[]> mockedResponse)
      Mock server response
      Parameters:
      name - Name of this "mocker". Must be a unique string (you are not allowed to add two mockers with the same name). Can be used to reset the mock after the test. Added to every http response as header "X-Mocked-By".
      requestMatcher - criteria which requests to mock
      mockedResponse - the mocked response body (e.g. html or image)
    • mockResponse

      public void mockResponse(String name, RequestMatcher requestMatcher, Supplier<org.openqa.selenium.remote.http.HttpResponse> mockedResponse)
    • reset

      public void reset(String name)
      Remove the mock when it's not needed anymore.
      Parameters:
      name - the unique name under which the mock was registered.
    • resetAll

      public void resetAll()
      Remove all mocks
    • filterRequest

      public @Nullable io.netty.handler.codec.http.HttpResponse filterRequest(io.netty.handler.codec.http.HttpRequest request, com.browserup.bup.util.HttpMessageContents contents, com.browserup.bup.util.HttpMessageInfo messageInfo)
      Specified by:
      filterRequest in interface com.browserup.bup.filters.RequestFilter