TrueBlueDrive / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

solo.takescreenshot doesnt take screen shot even on rooted phone #313

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have added permission in manifest file for external storage write
2. Then added the code for taking screenshot
3. when in run my junit test to test from apk file , I dont get screenshot. I 
still see permission denied error

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
3.4.1

Please provide any additional information below.
my test proj had provided external storage write permission and external 
storage write was not given in my application project
my apk was resigned and i was able to capture pictures using below code and 
save it here "/data/data/"+Common_functions.TARGET_PACKAGE_ID+"/files/""

        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap b = view.getDrawingCache();
        FileOutputStream fos = null;

        File sdcard = Environment.getExternalStorageDirectory();
        File pictureDir = new File(sdcard, "sample");
        try {

            String v_filename = "/data/data/"+Common_functions.TARGET_PACKAGE_ID+"/files/" + name+ System.currentTimeMillis() + ".jpg";
            fos = new FileOutputStream(v_filename);
            if (fos != null) {
                b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
                fos.close();
            }

Original issue reported on code.google.com by teja...@gmail.com on 21 Aug 2012 at 8:46

GoogleCodeExporter commented 9 years ago
takeScreenshot() requires one to add the permission tag to the application 
under test (AUT). Not the test project! The reason why your code works is that 
you are not saving it to sdcard. Therefore you do not need the permission tag 
in your application under test. Will open up this issue if behaviour of 
takeScreenshot() is modified to save to internal when permission is not 
present. 

Original comment by renasr...@gmail.com on 21 Aug 2012 at 9:34

GoogleCodeExporter commented 9 years ago
Until there is an official release, I would like to contribute my personal hack 
which works even when JUnit starts via command line, 
I used it with JUnit during the execution of different activities as well as 
during the dearDown();

    public void takeScreenshot(final String filename) {

            sleep(2000); //hack to ensure that the current view has been fully loaded
            View view = m_solo.getCurrentViews(FrameLayout.class).get(0).getRootView(); 
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache();
            Bitmap bitmap = view.getDrawingCache();

            File directory = new File("/mnt/sdcard/Robotium-Screenshots/");
            directory.mkdirs();

            if (bitmap != null) {
                try {
                    File outputFile = new File(directory, filename + ".jpg");
                    FileOutputStream ostream = new FileOutputStream(outputFile);
                    bitmap.compress(CompressFormat.JPEG, 100, ostream);
                    ostream.close();
                } catch (Exception e) {
                    logError(e.getMessage());
                }
            }
        }   

Original comment by d...@zarafonitis.com on 11 Jun 2013 at 11:11