Search code examples
javaselenium-webdriverautomated-testsbrowsermob

BrowserMob + selenium + java. How to create new response filter during on test scenario?


I need to create one more response filter during one test scenario. But now when I do this both filters work at the same time. How could I stop or override the previous one without stopping current browser instance?

Code example:

proxy.addResponseFilter((response, contents, messageInfo) -> {
        if (messageInfo.getOriginalUrl().contains(keyWord)) {
            contents.setTextContents(newResponse);
        }
    });

Solution

  • It's not currently possible to remove a javascript filter after you've added it, unfortunately. The new REST API that is currently in development will support this, though. There's an issue open to track this: https://github.com/lightbody/browsermob-proxy/issues/326