2014-02-18 33 views
18

我们得到的应用程序与Navigation Drawersupport.v4库。我们使用Robotium自动进行UI测试,一切正常,但Navigation Drawer可以随机冻结,因此一些测试可能会随机失败。Robotium UI测试应用程序与导航抽屉

这绝对不是Robotium问题,因为我看到Navigation Drawer在我的设备上的其他应用程序中,也在我自己的应用程序中被冻结。

我已经尝试过修复了Navigation Drawer从这个问题的前面回答:Why does DrawerLayout sometimes glitch upon opening?

它帮助和随机冻结从90%下降到约10%,但试运行的10%可能失败,这是非常不好的,尤其是对持续集成...

可能有人已经解决了这个问题?

+0

自从你问这个问题已经有一段时间了,你有没有找到解决这个问题的方法? – Mendhak

+1

不是,但我们的QA工程师建议尝试在循环中打开导航抽屉并检查其项目的可见性,如果可以,请打开环路。你可以试试这个方法 –

+0

听起来不错。我也一直在玩'solo.setNavigationDrawer(Solo.OPENED);',它出现在Robotium 5.1中。和'solo.sendKey(Solo.MENU);'几次(我连接菜单打开抽屉)。我会尝试你的建议,听起来很简单。 – Mendhak

回答

3

我遇到了与我们的Robotium测试相同的问题,并且我最终选择的解决方案是模拟拖动手势(真实用户如何滑动打开抽屉),而不是尝试单击抽屉切换或使用solo方法。我似乎注意到在运行比SDK 18更早的Android设备上经常出现间歇性故障。

我将此方法放在我们自己的子类Solo中,并且自从(超过数百次运行)以来我们没有失败测试。

/** 
* 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); 
} 
0

打开抽屉导航

/** 
* As we use app compat it seems Solo#setNavigationDrawer is not doing well 
* (drawer does not open, but the button is clicked) 
* 
* Same result for clickOnView(getView(android.R.id.home)) 
* 
* This code opens the navigation drawer on the main thread 
* Be aware : you need to provide your DrawerLayout id (you can do it in params) 
*/ 
public void openCompatNavigationDrawer() { 
    getInstrumentation().runOnMainSync(new Runnable() { 
     @Override 
     public void run() { 
      ((DrawerLayout) mSolo.getView(R.id.drawer_layout)) 
        .openDrawer(Gravity.LEFT); 
     } 
    }); 
} 

要点:solo.clickOnScreen(50, 50);

选择在抽屉导航列表项:

ListView listView = (ListView) solo.getView(R.id.left_drawer); View SwitchOrganizations = listView.getChildAt(0); solo.clickOnView(SwitchOrganizations);