How to modify HTTP requests in Android with Appium?

Just to give you some context, I’m automating a Web App, developed mostly in React Native, on an Android Device.
I need to capture a GET HTTP request, that contains a list of available products to buy, modify the request body, and add a couple thousand more products to test that the product page navigates properly.

I was having a look at this Playwright feature
here https://playwright.dev/docs/mock, and I was trying to figure how can I achieve this using Java and Appium.

I’ve found a few API mocking libraries like Mockito and RestAssured for Java, but from what I understood it only works on websites/web apps hosted locally in our computers…? (correct me if I’m wrong).

I’ve also seen that Selenium has this class called NetworkInterceptor, which is used to intercept requests at the browser level, using Chrome DevTools Protocol.
But the problem is that I’m not dealing with ChromeDrivers, but rather AndroidDrivers and Webviews.

Does anyone here had the same problem? If so, what solution(s) did you come up with?

Hey Guilherme, IIRC my team is using Charles Proxy’s rewrite feature to manipulate and re-send the request. Surely not the most performant solution, but we aimed for the most pragmatic solution, and this was Charles.

If you need more details I can bring you in contact with our test automation engineers.

Cheers :slight_smile:

1 Like

Until/unless Appium and the underlying drivers it interfaces with supports what you refer to, what you want to achieve is likely not possible directly from Appium for Android.

What has been done for Selenium in the past prior to CDP, for automation, I believe is use of BrowserMobProxy, which is similar to Charles Proxy that susanne mentions, but more automation friendly with API support. I would suggest you look into BrowserMobProxy for use with Appium.

It would mean however, you need to route the device/simulator network settings to go through the proxy for you to then modify the HTTP requests/responses. I am assuming you can either preset that on device/simulator, or use Appium to configure that part of it.

1 Like