How to intercept network with Selenium Java on LambdaTest cloud?
Hi Emma,
It’s easy to intercept network with Selenium Java on LambdaTest cloud. You can use the following code snippet to intercept network.
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();
Supplier<InputStream> message = () -> new ByteArrayInputStream(
"Creamy, delicious cheese!".getBytes(StandardCharsets.UTF_8));
NetworkInterceptor interceptor = new NetworkInterceptor(
driver,
Route.matching(req -> true)
.to(() -> req -> new HttpResponse()
.setStatus(200)
.addHeader("Content-Type", StandardCharsets.UTF_8.toString())
.setContent(message)));
You can also refer to the below GitHub repo for the above scenario -