1

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 :)

Brett Haines
  • 184
  • 3
  • 14

2 Answers2

1

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

Gabriel Porumb
  • 1,661
  • 1
  • 12
  • 21
  • Unfortunately the getOutput method hangs when it gets to the while loop... but I'll keep playing with it and see if I can get it working. I appreciate the response! – Brett Haines Jul 25 '14 at 16:44
  • It never hanged when I used it. And I did not filter the log by any string. I had the whole logcat put into the output variable. – Gabriel Porumb Jul 30 '14 at 06:40
  • I asked a friend of mine and he suggested that you may not be using uiautomator, but an instrumentation project instead. Here's what he told me: "In order to have log access you need to add this line in the manifest " – Gabriel Porumb Jul 30 '14 at 08:13
0

I use a shell script for both execution of the tests and also for printing a filtered logcat to textfile! You can do that to.

MoSCoW
  • 59
  • 1
  • 2
  • 5