xiaofans / robotium

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

Make takeScreenshot wait for Activity to be created #434

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The bug is about solo.takeScreenshot();

If you use solo.takeScreenshot() shortly after starting an activity, it will 
not be able to take a screenshot.

After going into the source code of takeScreenshot() method in Solo.java, I 
found that viewFetcher.getRecentDecorView(viewFetcher.getWindowDecorViews()) 
would  return null if an activity is just starting. The reason is that no 
decorview got in viewFetcher.getWindowDecorViews() is focused if the activity 
has not started completely.

I think the code should be revised like this in takeScreenshot():

        View decorView = null;
    while(decorView == null){
        View[] decorViews = viewFetcher.getWindowDecorViews();
        decorView = viewFetcher.getRecentDecorView(decorViews);
        sleep(500);
    }
    screenshotTaker.takeScreenshot(decorView, null);

Of course takeScreenshot(String name) and takeScreenshot(String name, int 
quality) will need being revised similarly.

Original issue reported on code.google.com by czxt...@gmail.com on 15 Apr 2013 at 7:38

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. It will be included in the next release.

Original comment by renasr...@gmail.com on 15 Apr 2013 at 10:20

GoogleCodeExporter commented 9 years ago
i got the same problem & the workaround i used was calling a 
waitforactivity(getcurrentactivity()) then solo.takeScreenshot().

sometimes solo.waitforactivity() can take some time but the workaround is 
working for me.

a solution in next release will be awesome :)

Original comment by khelifa....@gmail.com on 11 May 2013 at 9:59

GoogleCodeExporter commented 9 years ago
This has been fixed in Robotium 4.2. 

Original comment by renasr...@gmail.com on 25 Jun 2013 at 4:24