I'm currently testing an app that accesses a webpage and times how long it takes to get a result from said page. It records this time to LogCat like this:
Log.i("Time-taken", "" + timetaken);
I would like my testing app to pull these tagged logs and store them over multiple HTTP calls, then give different stats on them when the test is finished (average, median, etc). Is this something that can be done, or should I just set up a separate timing mechanism in the test method?
Thanks in advance :)
When using uiautomator with java I used this and it helped:
private StringBuilder getOutput(String command) {
try {
Process proc = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
StringBuilder output = new StringBuilder();
String line = "";
while ((line = stdInput.readLine()) != null) {
output.append(line);
}
stdInput.close();
return output;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
You can use like this:
StringBuilder logcat = getOutput("logcat -s 'Time-taken' -d");
-s is to isolate your strings/ log info
-d is to take the log and stop the logcat command