testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

Could an example for "How to Clear App Cache/Data" be added to the uiautomator example

Open TimB0 opened this issue 11 years ago • 3 comments

Im migrating to the new uiautomator version, but my existing method for clearing cache and data is no longer working. I think its because its the Java equivalent of an adb command, which I guess, will not work with the new uiautomator since the tests are running in an apk instead of through an adb shell. But that is just my guess. If you need any more info please let me know. Here is the code i used to use:

        try {
            Process process = Runtime.getRuntime().exec("system/bin/pm clear com.my.application");
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            int read;
            char[] buffer = new char[4096];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
            }
            reader.close();
            process.waitFor();

            return true;

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

TimB0 avatar Sep 15 '15 22:09 TimB0

I think this should be part of the test harness not UiAutomator, so this is more of a tools bug to be honest. for now can you just file a feature request here (https://code.google.com/p/android/issues/entry?template=Test%20Support%20Library%20feature) and we'll take a look.

slinzner-corp avatar Sep 15 '15 23:09 slinzner-corp

I agree...Im not suggesting this be a part of UiAutomator...Im just asking for some help as a user of Uiautomator for a technique to clear cache and cookies...Including it in the samples would be helpful to everyone who will be using it, especially the users who are migrating from UiAutomator 1.0. - since the architecture for how the tests run is totally different now.

TimB0 avatar Sep 15 '15 23:09 TimB0

Closing this as not sample related, please file a feature request here: https://code.google.com/p/android/issues/entry?template=Test%20Support%20Library%20feature

slinzner-corp avatar Sep 18 '15 20:09 slinzner-corp