zoukankan      html  css  js  c++  java
  • 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));
  • 相关阅读:
    【转】PostgreSQL与MySQL比较
    HIVE出现Read past end of RLE integer from compressed stream Stream for column 1 kind LENGTH position: 359 length: 359 range: 0错误
    HSDF查看各级目录的大小
    windows7搜索python java go php等其他文件内容
    Tomcat配置https后,并发较大时,频繁超时情况。
    Tomcat7配置Https
    部分手机浏览器存在将ajax请求当成广告过滤的情况,及解决方案
    百度广告联盟api probuf协议对接
    SQL查询时,根据日期范围查询周
    执行Hive出现Error running child : java.lang.OutOfMemoryError: Java heap space错误
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/4089942.html
Copyright © 2011-2022 走看看