Package com.codeborne.selenide.proxy
Class MockResponseFilter
java.lang.Object
com.codeborne.selenide.proxy.MockResponseFilter
- All Implemented Interfaces:
com.browserup.bup.filters.RequestFilter
@ParametersAreNonnullByDefault
public class MockResponseFilter
extends Object
implements com.browserup.bup.filters.RequestFilter
Selenide proxy filter allowing to mock any response
- Since:
- 6.9.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionio.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) void
mockBytes
(String name, RequestMatcher requestMatcher, int status, Supplier<byte[]> mockedResponse) Mock server responsevoid
mockBytes
(String name, RequestMatcher requestMatcher, Supplier<byte[]> mockedResponse) void
mockResponse
(String name, RequestMatcher requestMatcher, Supplier<org.openqa.selenium.remote.http.HttpResponse> mockedResponse) void
mockText
(String name, RequestMatcher requestMatcher, int status, Supplier<String> mockedResponse) void
mockText
(String name, RequestMatcher requestMatcher, Supplier<String> mockedResponse) void
Remove the mock when it's not needed anymore.void
resetAll()
Remove all mocks
-
Constructor Details
-
MockResponseFilter
public MockResponseFilter()
-
-
Method Details
-
mockText
-
mockText
public void mockText(String name, RequestMatcher requestMatcher, int status, Supplier<String> mockedResponse) -
mockBytes
-
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 mockmockedResponse
- 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
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
@Nullable public 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 interfacecom.browserup.bup.filters.RequestFilter
-