This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 6
May 2018

I have one requirement. I am automating one android app where i wanted to compare the APP result with API response. How can i achieve this scenario? Please help me on this.

  • created

    May '18
  • last reply

    May '18
  • 5

    replies

  • 381

    views

  • 2

    users

  • 2

    likes

  • 2

    links

Thank you @Prajith_KP for your valuable reply. I will check this. Do you have any document or any site for reference to achieve this for reference?

Don’t have any reference links if you want you can refer below sample which i roughly did
Below code is for GET method

function will accept URL and headers and return response

String[] get(String url, Map<String,String> headers) throws IOException {
client = new OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS)
.writeTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS)
.followRedirects(true).followSslRedirects(true).
build();
response_received= new String[3];
Request.Builder builder = new Request.Builder()
.url(url).header(“User-Agent”, “Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19”);
headers.forEach((key,value)->builder.addHeader(key, value));
Request request = builder.build();
System.out.println(ExecutionLogGenerator.Logger(classname)+"–> HTTP GET “+ url);
try (Response response = client.newCall(request).execute()){
System.out.println(ExecutionLogGenerator.Logger(classname)+”<-- HTTP “+response.code()+” “+url+” [Success : “+ response.isSuccessful()+”]"+" [Message :"+ response.message()+"]");
response_received[0]= String.valueOf(response.code());
response_received[1]= response.message();
response_received[2]= response.body().string();
return response_received;
}
}

but comparison its based on requirement you can go through the samples given here
https://github.com/json-path/JsonPath9 you will find something suitable for your requirement. :slightly_smiling_face: