stephenwang1011 / robotium

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

Sleeping before searching slows tests down #235

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Just as an example: Waiter.waitForView waits (e.g. 500 msecs) before doing the 
first search attempt. Is this really intended ? IMHO, sleeper.sleep() should be 
moved to the end of the loop. Same for other waitForXXX methods. Having X 
waitForXXX calls means that the test will last at least X * 0.5 secs.

    public View waitForView(int id){
        ArrayList<View> views = new ArrayList<View>();
        long startTime = System.currentTimeMillis();
        long endTime = startTime + SMALLTIMEOUT;
        while (System.currentTimeMillis() <= endTime) {
            sleeper.sleep();
            views = viewFetcher.getAllViews(false);
            for (View v : views) {
                if (v.getId() == id) {
                    views = null;
                    return v;
                }
            }
        }
        return null;
    }

Original issue reported on code.google.com by josefaic...@gmail.com on 21 Mar 2012 at 1:12

GoogleCodeExporter commented 9 years ago
The reason for the sleeps is to slow down the execution. This biggest issues 
with test automation for Android applications is the timing issues. There have 
been a lot of experiments with less sleeps, no sleeps, moved sleeps, etc and 
none of them have been successful. The execution is even now sometimes to fast 
for some applications. The waits are now as optimal they can get without 
compromising speed or stability. 

Original comment by renasr...@gmail.com on 21 Mar 2012 at 3:36

GoogleCodeExporter commented 9 years ago
The fact that a sleep is needed is fine, but can the while loop check the view 
first to see if it exists, then execute the sleep afterwards?

while (System.currentTimeMillis() <= endTime) {
    views = viewFetcher.getAllViews(false);
    for (View v : views) {
        if (v.getId() == id) {
            views = null;
        return v;
    }
    }
    sleeper.sleep();
}
        }

Original comment by mgmait...@gmail.com on 7 Mar 2014 at 3:29

GoogleCodeExporter commented 9 years ago
Yes, This is really slowing down tests. It should check the conditional before 
the sleep, 
Every 
Assert.assertEquals("text not equals", "Submit", solo.getText());
Assert.assertEquals("text not equals", "Cancel", solo.getText());

Adds unnecessary delay if the screen is not changing.  This is an easy fix. I 
don't understand why it was marked as WontFix

Original comment by shane...@gmail.com on 7 Mar 2014 at 3:46