robotium android



package test.java.com.zendaimoney.android.athena;

import com.jayway.android.robotium.solo.*;
import com.zendaimoney.android.athena.MainActivity;

import android.R;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.EditText;

public class MainActivityTest  extends ActivityInstrumentationTestCase2 {
 
    private Solo solo;
    private static Class<?> launcherActivityClass;
    private static final int Sleeptime1 = 2000;
   
    //此处为你要测试的apk的包名,这里我测得是豌豆荚2
    private static final String TARGET_PACKAGE_ID ="com.zendaimoney.android.athena";
    //此处的classname是你要测得apk的主类名,也就是进入apk第一个activity的类名
   // private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME ="com.zendaimoney.android.MainActivity";

    public MainActivityTest() {     
     super(TARGET_PACKAGE_ID,MainActivity.class);
        }
   
    public void setUp() throws Exception{
        solo=new Solo(getInstrumentation(), getActivity());
 }
   
    //登录是否成功
    public void testUI() throws Exception {
        solo.sleep(Sleeptime1);
       
        boolean expected = true;
        boolean actual=false;       
       
        Activity act=solo.getCurrentActivity();
        int id_account=act.getResources().getIdentifier("account", "id", act.getPackageName());
        int id_password=act.getResources().getIdentifier("passwd", "id", act.getPackageName());
       
        if(id_account!=0 && id_password!=0)
        {
          //View view1=act.findViewById(id_account);
          //solo.enterText(0, "appmanager");  //直接输入
          //solo.clickOnButton("登录");
         
          EditText editText1=(EditText)solo.getView(id_account);
          solo.enterText(editText1, "appmanager");
         
          EditText editText2=(EditText)solo.getView(id_password);
          solo.enterText(editText2, "123456");
          solo.clickOnButton("登录");
         
          int id_exitbtn=act.getResources().getIdentifier("exitbtn", "id", act.getPackageName());       
          if(id_exitbtn!=0)
          {
           actual=true;          
          }
          assertEquals("登录是否成功:", expected, actual);
          /*
         solo.enterText(0,"appmanager");
         solo.enterText(1,"123456");
        // solo.clickOnButton("登录");       
       
        
        // Activity act=solo.getCurrentActivity();
        // act.getResources().getIdentifier(name, defType, defPackage)
       // int id=act.getResources().getIdentifier
        
        
         Activity act=solo.getCurrentActivity();//获取Activity
         solo.getView(R.id.)
         int id=act.getResources().getIdentifier("登录", "id", act.getPackageName());//通过String的id获取int的id
         View view=act.findViewById(id);//获取View
         solo.clickOnView(view);//点击       
         solo.sleep(Sleeptime1);  
 */
         
          }
    }
       
       
        //登录成功后列表清单
        public void testList() throws Exception {
            solo.sleep(Sleeptime1);
            boolean expected = true;        
            boolean actual = solo.searchText("投资") && solo.searchText("客户提醒");
            Activity act=solo.getCurrentActivity();
            int id=act.getResources().getIdentifier("salarywran_num","id", solo.getCurrentActivity().getPackageName());
            View view=act.findViewById(id);       
            assertEquals("列表是否正确:", expected, actual);        
        }
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值