3

I have implemented Selenium with BrowserMob proxy in embedded mode.

I have also added a request and response filter to the proxy which successfully filters all the requests and responses. But how do I track a specific request, like implementing a callback function when that request receives a response. I also need to modify few objects based on the response which cannot be set as a static variable since there would be multiple tests running simultaneously. Is there any way to achieve this.? Any help or info would be really appreciated.

Current Filter Implementation : (just added the code as in the docs)

proxy.addRequestFilter(new RequestFilter() {
        @Override
        public HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {
            if (request.getMethod() == HttpMethod.POST) {
                /*
                 * Track this request and resume operations
                 * once the response is recieved
                 */
            }
            return null;
        }
    });

proxy.addResponseFilter(new ResponseFilter() {
        @Override
        public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
           if (/*required request receives response) {
            /*
             * should be able to pass(somehow need to access)
             * an variable to set the status  
             * 
             */
        }
    });
Naveen
  • 41
  • 5
  • Did you ever figure out a solution? I'm trying to do the same thing. I have 2-3 requests that get made once I open the app but I want the second one. addResponseFilter only gets me the first one. – learningruby347 Apr 24 '19 at 12:33

0 Answers0