lihuazhang / robotium

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

Screenshots do not get saved #579

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make sure target app has external write access
2. take screenshot
3.

What is the expected output? What do you see instead?
A screenshot in /mnt/sdcard/Robotium-Screenshots

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

Please provide any additional information below.
There is no error anywhere logged in logcat, test passes without problems.
The app under testing is visible when waiting before screenshot. I also tried 
with several different save paths in the Config file and PNG/JPG.
Nothing works, I can't get any output or error messages.

Relevant code:
solo.clickOnScreen(centerx, centery);
solo.sleep(1000);
solo.takeScreenshot();

Original issue reported on code.google.com by goo...@umito.nl on 23 Feb 2014 at 2:38

GoogleCodeExporter commented 9 years ago
public class ScreenshotsTaker extends 
ActivityInstrumentationTestCase2<PianoFragmentActivity> {

    private Solo solo;
    public ScreenshotsTaker() {
        super(PianoFragmentActivity.class);
    }

    @Override
    protected void setUp() throws Exception {       

        Config config = new Config();
//      config.screenshotFileType = ScreenshotFileType.PNG;
//      config.screenshotSavePath = Environment.getExternalStorageDirectory() + 
"/RobotiumTest/";
        solo = new Solo(getInstrumentation(), config);
        getActivity();
        super.setUp();
    }

    public void testTakeScreenshots() throws Exception
    {
        View scrollbarpiano = getActivity().findViewById(R.id.scrollbar_piano);
        int[] xy = new int[2];      
        scrollbarpiano.getLocationOnScreen(xy);
        int centerx = (scrollbarpiano.getWidth() / 2) + xy[0];
        int centery = (scrollbarpiano.getHeight() / 2) + xy[1];
        solo.clickOnScreen(centerx, centery);
        solo.sleep(1000);
        solo.takeScreenshot();

    }
}

Original comment by goo...@umito.nl on 23 Feb 2014 at 2:39

GoogleCodeExporter commented 9 years ago
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="***.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="***" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

</manifest>

Original comment by goo...@umito.nl on 23 Feb 2014 at 2:41

GoogleCodeExporter commented 9 years ago
Target package has also android.permission.WRITE_EXTERNAL_STORAGE permission 
set.

Original comment by goo...@umito.nl on 23 Feb 2014 at 2:41

GoogleCodeExporter commented 9 years ago
It looks like I finally got it working by disabling Hardware Acceleration in 
the target app. It looks like HW accel interferes with Robotium's ability to 
take screenshots. Is this a known issue?

Original comment by goo...@umito.nl on 23 Feb 2014 at 2:58

GoogleCodeExporter commented 9 years ago
Unfortunately it still stops working after a few tries. Files just don't get 
saved. 

Original comment by goo...@umito.nl on 23 Feb 2014 at 3:10

GoogleCodeExporter commented 9 years ago
It turns out it is due to having the solo.takeScreenshot() method as last 
method in the testsuite. When I add a solo.sleep(1000) after the last 
screenshot call it saves ok, even with HW accel on. I guess it's due to 
threading issue, where the screenshots are taken on a thread, while the test 
finishes and kills the testrunner, taking the screenshot thread with it. Maybe 
handle this more properly?

Original comment by goo...@umito.nl on 23 Feb 2014 at 3:22

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. Lets see what we can do to improve it. 

Original comment by renasr...@gmail.com on 24 Feb 2014 at 3:01

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

Original comment by renasr...@gmail.com on 18 Jun 2014 at 3:12

GoogleCodeExporter commented 9 years ago
Ok, great! What was the solution? 

Original comment by goo...@umito.nl on 18 Jun 2014 at 6:53

GoogleCodeExporter commented 9 years ago
We lock the instrumentation thread until the screenshot thread has finished. 
Thus preventing what could happen previously. 

Original comment by renasr...@gmail.com on 19 Jun 2014 at 4:35