appium / mitmproxy-java

A bridge between Python's mitmproxy and Java programs. Built on top of mitmproxy-node
Apache License 2.0
65 stars 21 forks source link

Unable to reflect response in android app using appium and Java #17

Open ashuaviator1987 opened 1 year ago

ashuaviator1987 commented 1 year ago

I am using below configuration.

  1. Installed MITM certificate on my emulator.
  2. Installed MITM proxy, websocket and other related dependecy as mentioned in appiumPro article

Part of code dealing with proxy is as per below ` List messages = new ArrayList<>();

    // remember to set local OS proxy settings in the Network Preferences
    proxy = new MitmproxyJava("C:\\Python311\\Scripts\\mitmdump.exe", (InterceptedMessage m) -> {
        if(

                m.getRequest().getUrl().toString().toLowerCase().startsWith(apiURL.toLowerCase()) &&
                m.getRequest().getMethod().equalsIgnoreCase("post")&&
                getJsonObject(new String(m.getRequest().getBody())).hasNonNull("operationName")&&
                getJsonObject(new String(m.getRequest().getBody())).get("operationName").asText().equalsIgnoreCase("getPharamcyTATInfo")
        )
        {

                JsonNode responseBodyJson = getJsonObject(new String(m.getResponse().getBody()));
                String modifiedResp = updateValuesInJson(responseBodyJson.toString(),
                        "data.getSkuInfo.tatInfo.tatResponse.inventoryExist",false,
                        "data.getSkuInfo.tatInfo.tatResponse.items[0].exist",false);
                m.getResponse().setBody(modifiedResp.getBytes(StandardCharsets.UTF_8));
                m.getResponse().getHeaders().add(new String[]{"My Test Resp Header","Header Value"});
                messages.add(m);
        }
        return m;
    });
    proxy.start();

    login(initializeDriver(testMethod),credentialManager);

`

now I have printed the intercepted message and modified response. but the app is still receiving the unmodified request. when I do below ` messages.forEach( x->{ LOGGER.info("########Request Operation : "+x.toString() +getJsonObject(new String(x.getRequest().getBody())).get("operationName")); LOGGER.info("########### Response Body :" +new String(x.getResponse().getBody())); }

    );`

i see the proper response (modified one), this response never made it app, it is still showing the normal behaviour.

P.S. the app is Android native app Please advice

ashuaviator1987 commented 1 year ago

@jlipps can we do a paid support for this issue