• Robotium 测试方法


    1.检查CheckBox 是否选上,用solo.isCheckBoxChecked( “text” )。

      有时候checkBox 没有相关的text,这时要用solo.isCheckBoxChecked(index) 。 
    2. 如果页面上相同的string有多个,可以用index来区分。

      如solo.clickOnText(text,index),第一次匹配index=1,第N次匹配index=n。
    3.发送sendkey命令时,用sendKeys (String keysSequence)可以指定发送动作重复的次数,唯一需要注意的就是这里面KeysSequence不用想普通命令时写上 KeyEvent.KEYCODE_这些,直接写sendKeys(i*KEYEVENT),比如sendKeys(256*DEL)就是重复256次删除动作

    4. InstrumentationTestCase可以用来模拟触摸屏和按键的处理,为了避免误操作,在测需要触摸和按键的case前最好关闭模拟器或设备的触摸功能:setActivityInitialTouchMode(false);

    5. 触摸和按键可以通过TouchUtils.clickView(this, button/view);来实现

    6、断言  assert:

     assertEquals(“string”,expect,actual):判断实际值与期待值是否相等,相等判定为真,否则为false,并报错string。

    8.EditText 处理

    用solo.enterText(0,"text"), 有时会发生无法输入string的现象。

     1 EditText fNameInputField = solo.getEditTextWithHint("string")
     2 
     3 assertNotNull (“string of error hint”,fNameInputField);
     4 
     5 solo.enterText (fNameInputField, "your string")
     6 
     7 //getEditTextWithHint的函数定义:
     8 
     9  for (EdutText view :getCurrentEditText())
    10 
    11 {    
    12     CharSequence target=view.getHint();
    13 
    14     Pattern pattern=Pattern.compile(hintRegex);
    15 
    16     Matcher matcher=pattern.matcher(target);
    17 
    18     if (matcher.find())
    19 
    20     {
    21         return view;
    22     }
    23 }
    24     

    10.View 处理:

    ArrayList<View> viewList =getCurrentViews();

    index=viewList.indexOf(view);//当前view对应的index

    如果要得到其他View  viewList.get(index+othernumber)

    11.instrumentation 对key的处理  private instrumentation instru;instru.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK)

    solo实例的创建方法 helloinstrumentation=getInstrumentation   solo =new Solo(helloinstrumentation)

    12.屏幕上拉至顶    

    1 ArrayList<Listview> listviews =solo.getCurrentListViews(); 
    2 if (listviews.size()>0)  {
    3 
    4     TouchUtils.scrollToTop(this,getActivity,listviews.get(0));
    5 }
    6 assertFalse (solo.searchText(subject));

    13.点击下拉框

    1 ArrayList<Spinner> spinner=solo.getCurrentSpinners();
    2 solo.clickOnView(spinners.get(index));
  • 相关阅读:
    Django Admin管理后台详解3(转)
    django常用命令(转)
    Django Admin管理后台详解5(转)
    Django Admin管理后台详解4(转)
    java程序启动停止(转)
    maven运行stucts报404的解决方案
    vista和win7 下安装 Microsoft Web Application Stress Tool
    学习JQuery【一】:选择对象
    我为什么写博客
    代码度量工具——SourceMonitor的学习和使用
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/4089942.html
Copyright © 2020-2023  润新知