Selenium 4 with Java: Mocking/stubbing network requests

1.2k views Asked by At

Is there a more or less comprehensive guide on how to mock/stub network requests in Selinum 4? This is, as I see it, the main strength of Cypress (as well as ease of access for frontend developers), and I've been waiting to see a smooth way to do this with Selenium without lots of extra software.

In cypress, I can just open the developer -> network tab in Chrome, copy the request, and create a route. Then voilla! - the page can be opened with all the data in place as if the page had been accessed and data sent to the backend manually.

Anyone know how/where to get started with this in Selenium 4? Or have I misunderstood completely when thinking that this is a new feature?

1

There are 1 answers

3
DJSDev On

Selenium's BiDirectional API seems to be what you're after. They have a network interception example in both Java and Kotlin on their website. Hopefully that's enough to get you started.

https://www.selenium.dev/documentation/webdriver/bidirectional/chrome_devtools/bidi_api/#network-interception