arucard17 / robotium

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

Instrumentation run failed due to 'java.lang.OutOfMemoryError' if I use solo.takeScreenshot #571

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I run a series of test methods (more than 10) and I take some screenshot 
during every test (about 5 screenshots for test)

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

I'm having an OutOfMemoryException when I enable taking screenshot during my 
test with Robotium. If I disable taking screenshot it's ok.

[2014-01-09 10:53:28 - MyAppTest] Test run failed: Instrumentation run failed 
due to 'java.lang.OutOfMemoryError'

What version of the product are you using? On what operating system?
I had this problem on versions 4.2, 4.3, 4.1

Please provide any additional information below.

As you can see in the code below I've a variable that let me decide if I want 
to take screenshot or not; if I enable taking screenshot I've the error above 
after I run about 10 test methods (I take from 1 to 10 screenshot for each 
test).

This is the code I run:
public class TestApk extends ActivityInstrumentationTestCase2{
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.xxx.xxxnew.activities.XxxActivity";
    private static Class launcherActivityClass;

    private static final boolean ENABLE_SCREENSHOT_CAPTURE = true;
    private static final int SLEEP_TIME = 4000;

    static{
        try{
            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e){
            throw new RuntimeException(e); 
        } 
    }

    @SuppressLint("NewApi")
    public TestApk()throws ClassNotFoundException{
        super(launcherActivityClass); 
    }

    private Solo solo;

    @Override
    protected void setUp() throws Exception {
        solo = new Solo(getInstrumentation(),getActivity());
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }

    public void test_login_001(){
    // ... some Robotium code
    if(ENABLE_SCREENSHOT_CAPTURE){
            solo.sleep(SLEEP_TIME);
            solo.takeScreenshot("login_001_c");
        }
    // ... some Robotium code   
    if(ENABLE_SCREENSHOT_CAPTURE){
            solo.sleep(SLEEP_TIME);
            solo.takeScreenshot("login_001_c");
        }
    }   

    public void test_login_002_a(){
    // ... some Robotium code
    if(ENABLE_SCREENSHOT_CAPTURE){
            solo.sleep(SLEEP_TIME);
            solo.takeScreenshot("login_002_a");
        }
    // ... some Robotium code   
    if(ENABLE_SCREENSHOT_CAPTURE){
            solo.sleep(SLEEP_TIME);
            solo.takeScreenshot("login_001_2");
        }
    }   

    //other test methods
}

This is the error from LogCat:

01-09 11:16:55.619: I/dalvikvm-heap(13717): Forcing collection of 
SoftReferences for 8294416-byte allocation
01-09 11:16:55.659: D/dalvikvm(13717): GC_BEFORE_OOM freed 10K, 14% free 
112688K/129624K, paused 37ms, total 38ms
01-09 11:16:55.659: E/dalvikvm-heap(13717): Out of memory on a 8294416-byte 
allocation.
01-09 11:16:55.659: I/dalvikvm(13717): "main" prio=5 tid=1 RUNNABLE
01-09 11:16:55.659: I/dalvikvm(13717):   | group="main" sCount=0 dsCount=0 
obj=0x40e68b38 self=0x40e4a0b8
01-09 11:16:55.659: I/dalvikvm(13717):   | sysTid=13717 nice=0 sched=0/0 
cgrp=apps handle=1074288092
01-09 11:16:55.659: I/dalvikvm(13717):   | state=R schedstat=( 0 0 0 ) utm=1943 
stm=453 core=0
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.graphics.Bitmap.nativeCopy(Native Method)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.graphics.Bitmap.copy(Bitmap.java:471)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
com.jayway.android.robotium.solo.ScreenshotTaker.getBitmapOfView(ScreenshotTaker
.java:215)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
com.jayway.android.robotium.solo.ScreenshotTaker.access$400(ScreenshotTaker.java
:32)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
com.jayway.android.robotium.solo.ScreenshotTaker$ScreenshotRunnable.run(Screensh
otTaker.java:326)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.os.Handler.handleCallback(Handler.java:725)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.os.Handler.dispatchMessage(Handler.java:92)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.os.Looper.loop(Looper.java:137)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
android.app.ActivityThread.main(ActivityThread.java:5328)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
java.lang.reflect.Method.invokeNative(Native Method)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
java.lang.reflect.Method.invoke(Method.java:511)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
01-09 11:16:55.659: I/dalvikvm(13717):   at 
dalvik.system.NativeStart.main(Native Method)
01-09 11:16:55.659: D/AbsListView(13717): [unregisterDoubleTapMotionListener]
01-09 11:16:55.659: I/MotionRecognitionManager(13717):   .unregisterListener : 
/ listener count = 0->0,  
01-09 11:16:55.659: D/AbsListView(13717): unregisterIRListener() is called 
01-09 11:16:55.659: D/AndroidRuntime(13717): Shutting down VM
01-09 11:16:55.659: W/dalvikvm(13717): threadid=1: thread exiting with uncaught 
exception (group=0x40e67ac8)
01-09 11:16:55.669: E/AndroidRuntime(13717): FATAL EXCEPTION: main
01-09 11:16:55.669: E/AndroidRuntime(13717): java.lang.OutOfMemoryError
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.graphics.Bitmap.nativeCopy(Native Method)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.graphics.Bitmap.copy(Bitmap.java:471)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
com.jayway.android.robotium.solo.ScreenshotTaker.getBitmapOfView(ScreenshotTaker
.java:215)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
com.jayway.android.robotium.solo.ScreenshotTaker.access$400(ScreenshotTaker.java
:32)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
com.jayway.android.robotium.solo.ScreenshotTaker$ScreenshotRunnable.run(Screensh
otTaker.java:326)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.os.Handler.handleCallback(Handler.java:725)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.os.Handler.dispatchMessage(Handler.java:92)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.os.Looper.loop(Looper.java:137)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
android.app.ActivityThread.main(ActivityThread.java:5328)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
java.lang.reflect.Method.invokeNative(Native Method)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
java.lang.reflect.Method.invoke(Method.java:511)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
01-09 11:16:55.669: E/AndroidRuntime(13717):    at 
dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by flavioca...@gmail.com on 9 Jan 2014 at 10:30

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. Lets what we can do about this. 

Original comment by renasr...@gmail.com on 9 Jan 2014 at 11:56

GoogleCodeExporter commented 9 years ago
Thanks again for reporting this. This has been fixed in 5.1. 

Original comment by renasr...@gmail.com on 17 Mar 2014 at 6:09

GoogleCodeExporter commented 9 years ago
Thanks again for reporting this. This has been fixed in 5.1. 

Original comment by renasr...@gmail.com on 17 Mar 2014 at 6:09

GoogleCodeExporter commented 9 years ago
This bug is still persistent in Robotium 5.2.1.

I found this bug on a tablet when I try take more screenshots on a 10 inch 
tablet from Genymotion.

Original comment by bdtestmo...@gmail.com on 18 Dec 2014 at 2:53