robotium整理(三)

转载地址:http://blog.csdn.net/zqilu/article/details/12854899

将robotium中testcase一条一条执行

首先需要建xml文件将testcase加入到文件中如

<?xml version="1.0" encoding="UTF-8"?>
<Project>
<PackageName name="com.tmall.wireless.test">
    <Class name="MainTest">
        <method>
            <include name="testAInfomation"></include>
            <include name="testBTip"></include>
            <include name="testCDrag"></include>
            <include name="testDAttention"></include>
        </method>
    </Class>
    <Class>
        <method>
            <include name="testABtest"></include>
        </method>
    </Class>
</PackageName>
<PackageName name="test">
 <Class name="testSearch">
     <method>
         <include name="testASearch"></include>
         <include name="testBshortcut"></include>
     </method>
 </Class>
</PackageName>
</Project>

然后新建java文件读取这个xml文件

public class ReadXml{

       

           public static void main(String[] args) throws Exception{

            Process pro; 

            Boolean buff=false;        //判断命令是否执行失败

            String command=null;    //dos命令

            List <String> packageNames=new ArrayList<String>();

            List<String>classNames=new ArrayList<String>();

            String methodName=null;

           DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();

           DocumentBuilder builder=dbf.newDocumentBuilder();

           Document doc=(Document)builder.parse("文件名")    //如果想已参数形式传入则为 args[0]

           Element root=doc.getDocumentElement();

           NodeList pm=root.getElementsByTagName("packageName");

          NodeList cm=null;

         NodeList mm=null;

        NodeList tc=null;

        for(int i=0;i<pm.getLength();i++){

             cm=((Element)pm.item(i)).getElementsByTagName("className");

             packageNames.add(((Element)pm.item(i)).getAttribute("name"));  //从xml文件中读取到包名

            for(int j=0;j<cm.getLength();j++){

                  mm=((Element)cm.item(j)).getElementsByTagName("method");

                  classNames.add(packageNames.get(i)+"."+((Element)cm.item(i)).getAttribute("name")); //从xml文件中读取包名.类名

                  for(int k=0;k<mm.getLength();k++){

                         tc=((Element)mm.item(k)).getElementsByTagName("include");

                         for(int m=0;m<tc.getLength();m++){

                            methodName=((Element)tc.item(m)).getAttribute("name");

                            command="adb shell am instrumentation -e "+classnames.get(j)+"#"+methodName+" -                                              w"+packageName.get(i)+"/android.test.InstrumentationTestRunner" ;

                            proc= Runtime().getRuntime().exec(command);  //执行dos命令

                           BufferedReader br=new BuffererReader(new InputStreamReader(proc.getInputStream())); //读取执行命令的log信息

                           String line=br.readLine();

                            while(line !=null){

                                    if(line.maches(".* INSTRUMENTATION_FAILED.*$")){

                                       //log中是否含有这样的错误信息

                                           buff=true;

                                           break;

                                   } 

                                   line=br.readLine();                                   

                            }

                          if(buff){//如果执行失败就重现执行一次。再次失败就失败把!

                           proc=Runtime.getRuntime().exec(command);

                            buff=false;

                           }

                           

                   }

              }

               

        }

 }

                  

}

}

方法比较笨,大家如果有好的想法可以讨论下!!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值