Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robotium UI testing for app with Navigation Drawer

We got the app with Navigation Drawer from support.v4 library. We automating UI testing with Robotium and everything is ok, but Navigation Drawer can freeze randomly so some tests can fail randomly.

This is definitely not a Robotium problem, because I saw how Navigation Drawer gets freezed in some other apps on my device, also in my own apps.

I already tried fix for Navigation Drawer from this question's anwer: Why does DrawerLayout sometimes glitch upon opening?

It helped and random freezes decreased from 90% to about 10%, but 10% of test runs can fail and this is very bad, especially for Continuous Integration...

May be someone already fixed this problem?

like image 204
Artem Zinnatullin Avatar asked Feb 18 '14 09:02

Artem Zinnatullin


1 Answers

I encountered the same problem with our Robotium tests and the solution I ended up going with was to simulate a drag gesture (how a real user would swipe open the drawer) instead of trying to click the drawer toggle or using the solo methods. I seemed to notice the intermittent failues more often on devices running Android older than SDK 18.

I placed this method in our own subclass of Solo and we haven't had a failing test since (over hundreds of runs).

/**
 * Open the navigation drawer with a drag gesture. Click based triggering is
 * flaky on SDK < 18
 */
public void openNavigationDrawer() {
    Point deviceSize = new Point();
    getCurrentActivity().getWindowManager().getDefaultDisplay().getSize(deviceSize);

    int screenWidth = deviceSize.x;
    int screenHeight = deviceSize.y;
    int fromX = 0;
    int toX = screenWidth / 2;
    int fromY = screenHeight / 2;
    int toY = fromY;

    this.drag(fromX, toX, fromY, toY, 1);
}
like image 157
swanson Avatar answered Oct 20 '22 05:10

swanson