0

我正在尝试使用 Robotium 验证大型列表的内容,由于某种原因,一旦程序到达可见列表的底部,Robotium 将开始滚动,并继续滚动直到它到达列表的底部。我能做些什么来防止这种情况发生吗?理想情况下,程序将验证可见内容,滚动到足以显示一段未验证的内容,然后一旦验证,滚动到底部,最终允许测试应用程序验证列表中的所有内容。

这是我正在使用的代码:

public void testCatalogLinkContent(){
        //VERIFY USER IS ON HOMEPAGE
        try {
            solo.sleep(3000);
            assertTrue(solo.searchText(" Apps")) ;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        //CLICK ON CATALOG      
        try{
            solo.clickOnText(" Apps");
                }catch(Exception e){
                    e.printStackTrace();
                }
        //Search for Music in menu
        if(solo.searchText(RECOMMENDED)==false){
            Log.e(TAG, RECOMMENDED + " Not found!!!"); 

        }else{
            Log.i(TAG, RECOMMENDED + " Found"); 
        }

        //Search for UAT  in menu
        if(solo.searchText(UAT)==false){
            Log.e(TAG,  UAT + " Not found!!!"); 

        }else{
            Log.i(TAG, UAT  + " Found"); 
        }

        //Search for  NEW APPS in menu
        if(solo.searchText(NEW)==false){
            Log.e(TAG, NEW  + " Not found!!!"); 

        }else{
            Log.i(TAG, NEW + " Found"); 
        }

        //Search for TOP SELLERS in menu
        if(solo.searchText(TOPSELLER)==false){
            Log.e(TAG, TOPSELLER + " Not found!!!"); 

        }else{
            Log.i(TAG, TOPSELLER + " Found"); 
        }

        if(solo.searchText(TOPDOWNLOAD)==false){
            Log.e(TAG, TOPDOWNLOAD  + " Not found!!!"); 

        }else{
            Log.i(TAG, TOPDOWNLOAD  + " Found"); 
        }

        //Search for EA in menu
        if(solo.searchText(EA)==false){
            Log.e(TAG, EA  + " Not found!!!"); 

        }else{
            Log.i(TAG, EA  + " Found"); 
        }

        //Search for FEATURED in menu
        if(solo.searchText(FEATURED)==false){
            Log.e(TAG, FEATURED + " Not found!!!"); 

        }else{
            Log.i(TAG, FEATURED + " Found"); 
        }
        //Search for GAMES in menu
        if(solo.searchText(GAMES)==false){
            Log.e(TAG, GAMES + " Not found!!!"); 

        }else{
            Log.i(TAG, GAMES + " Found"); 
        }
        //Search for  APPS in menu
        if(solo.searchText(APPS)==false){
            Log.e(TAG, APPS + " Not found!!!"); 

        }else{
            Log.i(TAG, APPS  + " Found"); 
        }
        //Search for SOCIAL  in menu
        if(solo.searchText(SOCIAL)==false){
            Log.e(TAG, SOCIAL + " Not found!!!"); 

        }else{
            Log.i(TAG, SOCIAL  + " Found"); 
        }
        //Search for ENTERTAINMENT in menu
        if(solo.searchText(ENTERTAINMENT)==false){
            Log.e(TAG, ENTERTAINMENT + " Not found!!!"); 

        }else{
            Log.i(TAG,ENTERTAINMENT  + " Found"); 
        }
        //Search for THEMES  in menu
        if(solo.searchText(THEMES)==false){
            Log.e(TAG, THEMES  + " Not found!!!"); 

        }else{
            Log.i(TAG, THEMES  + " Found"); 
        }
        //Search for TOOLS  in menu
        if(solo.searchText(TOOLS)==false){
            Log.e(TAG, TOOLS + " Not found!!!"); 

        }else{
            Log.i(TAG, TOOLS  + " Found"); 
        }
        //Search for  NEWSin menu
        if(solo.searchText(NEWS)==false){
            Log.e(TAG, NEWS  + " Not found!!!"); 

        }else{
            Log.i(TAG, NEWS + " Found"); 
        }
        //Search for READING in menu
        if(solo.searchText(READING)==false){
            Log.e(TAG, READING + " Not found!!!"); 

        }else{
            Log.i(TAG, READING + " Found"); 
        }
        //Search for MONEY in menu
        if(solo.searchText(MONEY)==false){
            Log.e(TAG, MONEY + " Not found!!!"); 

        }else{
            Log.i(TAG, MONEY + " Found"); 
        }
        //Search for SHOPPING in menu
        if(solo.searchText(SHOPPING)==false){
            Log.e(TAG, SHOPPING  + " Not found!!!"); 

        }else{
            Log.i(TAG, SHOPPING  + " Found"); 
        }
        //Search for FITNESS in menu
        if(solo.searchText(FITNESS)==false){
            Log.e(TAG, FITNESS + " Not found!!!"); 

        }else{
            Log.i(TAG, FITNESS  + " Found"); 
        }
        //Search for TRAVEL  in menu
        if(solo.searchText(TRAVEL)==false){
            Log.e(TAG,TRAVEL + " Not found!!!"); 

        }else{
            Log.i(TAG, TRAVEL  + " Found"); 
        }
        //Search for BUSINESS  in menu
        if(solo.searchText(BUSINESS)==false){
            Log.e(TAG, BUSINESS + " Not found!!!"); 

        }else{
            Log.i(TAG, BUSINESS  + " Found"); 
        }
        //Search for SPANISH in menu
        if(solo.searchText(SPANISH)==false){
            Log.e(TAG, SPANISH + " Not found!!!"); 

        }else{
            Log.i(TAG, SPANISH + " Found"); 
        }
    }
4

3 回答 3

0

Robotium 的工作方式是“扫描”布局,因此当您指示它时solo.searchText(),它将查找您指定的任何内容,如果在当前可见区域中找不到它,它将滚动您的视图直到找到它(或它放弃了)。我的猜测是它没有找到文本" Apps",因为你的文本真的是"Apps",并且由于它找不到它,你会得到你指定的行为,“无限滚动”。

于 2012-06-19T21:07:10.693 回答
0

所以要解决这个问题,这是我必须做的:

public void testCatalogLinkContent(){
        //VERIFY USER IS ON HOMEPAGE
        try {
            solo.sleep(3000);
            assertTrue(solo.searchText("Apps")) ;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        //CLICK ON CATALOG      
        try{
            solo.clickOnText("Apps");
                }catch(Exception e){
                    e.printStackTrace();
                }
        //Search for Music in menu
        if(solo.searchText(RECOMMENDED)==false){
            Log.e(TAG, RECOMMENDED + " Not found!!!"); 

        }else{
            Log.i(TAG, RECOMMENDED + " Found"); 
        }

        //Search for UAT  in menu
        if(solo.searchText(UAT)==false){
            Log.e(TAG,  UAT + " Not found!!!"); 

        }else{
            Log.i(TAG, UAT  + " Found"); 
        }

        //Search for  NEW APPS in menu
        if(solo.searchText(NEW)==false){
            Log.e(TAG, NEW  + " Not found!!!"); 

        }else{
            Log.i(TAG, NEW + " Found"); 
        }

        //Search for TOP SELLERS in menu
        if(solo.searchText(TOPSELLER)==false){
            Log.e(TAG, TOPSELLER + " Not found!!!"); 

        }else{
            Log.i(TAG, TOPSELLER + " Found"); 
        }
        //Search for top downloaded
        if(solo.searchText(TOPDOWNLOAD)==false){
            Log.e(TAG, TOPDOWNLOAD  + " Not found!!!"); 

        }else{
            Log.i(TAG, TOPDOWNLOAD  + " Found"); 
        }

        //Search for EA in menu
        if(solo.searchText(EA)==false){
            Log.e(TAG, EA  + " Not found!!!"); 

        }else{
            Log.i(TAG, EA  + " Found"); 
        }
        solo.scrollUp();
        //Search for FEATURED in menu
        if(solo.searchText(FEATURED)==false){
            Log.e(TAG, FEATURED + " Not found!!!"); 

        }else{
            Log.i(TAG, FEATURED + " Found"); 
        }
        solo.scrollUp();
        //Search for GAMES in menu
        if(solo.searchText(GAMES)==false){
            Log.e(TAG, GAMES + " Not found!!!"); 

        }else{
            Log.i(TAG, GAMES + " Found"); 
        }
        solo.scrollUp();
        //Search for APPS in menu
        if(solo.searchText(APPS)==false){
            Log.e(TAG, APPS + " Not found!!!"); 

        }else{
            Log.i(TAG, APPS  + " Found"); 
        }
        solo.scrollUp();
        //Search for SOCIAL  in menu
        if(solo.searchText(SOCIAL)==false){
            Log.e(TAG, SOCIAL + " Not found!!!"); 

        }else{
            Log.i(TAG, SOCIAL  + " Found"); 
        }
        solo.scrollUp();
        //Search for ENTERTAINMENT in menu
        if(solo.searchText(ENTERTAINMENT)==false){
            Log.e(TAG, ENTERTAINMENT + " Not found!!!"); 

        }else{
            Log.i(TAG,ENTERTAINMENT  + " Found"); 
        }
        solo.scrollUp();
        //Search for MUSIC  in menu
                if(solo.searchText(MUSIC)==false){
                    Log.e(TAG, MUSIC  + " Not found!!!"); 

                }else{
                    Log.i(TAG, MUSIC  + " Found"); 
                }
                solo.scrollUp();
        //Search for THEMES  in menu
        if(solo.searchText(THEMES)==false){
            Log.e(TAG, THEMES  + " Not found!!!"); 

        }else{
            Log.i(TAG, THEMES  + " Found"); 
        }
        solo.scrollUp();
        //Search for TOOLS  in menu
        if(solo.searchText(TOOLS)==false){
            Log.e(TAG, TOOLS + " Not found!!!"); 

        }else{
            Log.i(TAG, TOOLS  + " Found"); 
        }
        solo.scrollUp();
        //Search for  NEWSin menu
        if(solo.searchText(NEWS)==false){
            Log.e(TAG, NEWS  + " Not found!!!"); 

        }else{
            Log.i(TAG, NEWS + " Found"); 
        }
        solo.scrollUp();
        //Search for SPORTS  in menu
                if(solo.searchText(SPORTS)==false){
                    Log.e(TAG, SPORTS  + " Not found!!!"); 

                }else{
                    Log.i(TAG, SPORTS  + " Found"); 
                }
                solo.scrollUp();
        //Search for READING in menu
        if(solo.searchText(READING)==false){
            Log.e(TAG, READING + " Not found!!!"); 

        }else{
            Log.i(TAG, READING + " Found"); 
        }
        solo.scrollUp();
        //Search for MONEY in menu
        if(solo.searchText(MONEY)==false){
            Log.e(TAG, MONEY + " Not found!!!"); 

        }else{
            Log.i(TAG, MONEY + " Found"); 
        }
        //Search for SHOPPING in menu
        if(solo.searchText(SHOPPING)==false){
            Log.e(TAG, SHOPPING  + " Not found!!!"); 

        }else{
            Log.i(TAG, SHOPPING  + " Found"); 
        }
        //Search for FITNESS in menu
        if(solo.searchText(FITNESS)==false){
            Log.e(TAG, FITNESS + " Not found!!!"); 

        }else{
            Log.i(TAG, FITNESS  + " Found"); 
        }
        //Search for TRAVEL  in menu
        if(solo.searchText(TRAVEL)==false){
            Log.e(TAG,TRAVEL + " Not found!!!"); 

        }else{
            Log.i(TAG, TRAVEL  + " Found"); 
        }
        //Search for BUSINESS  in menu
        if(solo.searchText(BUSINESS)==false){
            Log.e(TAG, BUSINESS + " Not found!!!"); 

        }else{
            Log.i(TAG, BUSINESS  + " Found"); 
        }
        //Search for SPANISH in menu
        if(solo.searchText(SPANISH)==false){
            Log.e(TAG, SPANISH + " Not found!!!"); 

        }else{
            Log.i(TAG, SPANISH + " Found"); 
        }
    }

在每次搜索之前(和之后),我插入了 solo.scrollUp();

这不是最漂亮的方法,也不是最有效的方法,但它现在有效。

感谢大家的帮助。

于 2012-06-19T22:46:30.347 回答
0

我遇到了类似的问题。似乎机器人在搜索文本时会自动向下滚动,但也会自动向下滚动。说在方法A中它搜索一些带有资源ID的视图,然后向下滚动到底部以找到所有这些视图,如果在方法B中向上滚动或滚动到顶部,它就不起作用;如果仅在方法 A 中向上滚动或滚动到顶部,它仍然有效。很奇怪的东西。

于 2015-03-25T12:55:42.970 回答