Skip to content

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

@ashuaviator1987

Description

@ashuaviator1987

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions